13 Replies - 804 Views - Last Post: 23 June 2013 - 11:54 AM Rate Topic: -----

#1 gunapriyan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 16-September 12

Data Grid Issue

Posted 22 June 2013 - 03:55 AM

Friends,

I wrote the following code;

Private Sub Form_Load()
	'On Error Resume Next
	Dim id As String
	Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
	Adodc1.RecordSource = "select * from table1"
	id = Text1.Text
	Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
	Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID='" & id & "'"
	Set DataGrid1.DataSource = Adodc2
	Adodc2.Recordset.Sort = "ID"
End Sub


But DataGrid shows all the record instead of one Record. Even I had used SELECT * FROM TABLE2 where ID='" & id & "'". But it is not working....

Please advise me.

Guna

This post has been edited by andrewsw: 22 June 2013 - 04:46 AM
Reason for edit:: Please use CODE tags


Is This A Good Question/Topic? 0
  • +

Replies To: Data Grid Issue

#2 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: Data Grid Issue

Posted 22 June 2013 - 04:18 AM

is your ID field in table is string? i think it's looks like integer to me.

This post has been edited by andrewsw: 22 June 2013 - 04:42 AM
Reason for edit:: No need to quote the entire previous post

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3181
  • View blog
  • Posts: 10,659
  • Joined: 12-December 12

Re: Data Grid Issue

Posted 22 June 2013 - 04:44 AM

I suspect the ID would work even with the quotes - I haven't checked.

But @OP you have switched from table1 to table2 in your sql statements.

This post has been edited by andrewsw: 22 June 2013 - 04:47 AM

Was This Post Helpful? 0
  • +
  • -

#4 gunapriyan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 16-September 12

Re: Data Grid Issue

Posted 22 June 2013 - 11:51 AM

Friends,

Thanks for your replies.

I am enclosing herewith the Table Structure and Query Execution for your kind perusal.

There is no problem in query. It was executed successfully and pick up only one row.

But in VB, It won't effect.

And I need the data from Table2 only.

It need to be displayed in Data Grid.

Please advise me.

Thanks & Regards,

Guna

Attached image(s)

  • Attached Image
  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3181
  • View blog
  • Posts: 10,659
  • Joined: 12-December 12

Re: Data Grid Issue

Posted 22 June 2013 - 12:01 PM

You are running this code on Form_Load and there will be nothing in the textbox unless you have set a default value.

Use this to test the value:

Dim id as String
MsgBox id

This post has been edited by andrewsw: 22 June 2013 - 12:02 PM

Was This Post Helpful? 0
  • +
  • -

#6 gunapriyan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 16-September 12

Re: Data Grid Issue

Posted 22 June 2013 - 12:49 PM

Friend,

It showing the Value of Text Box.

See the following Code;

Private Sub Form_Load()
    'On Error Resume Next
    Dim id As String
    Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
    Adodc1.RecordSource = "select * from table1"
    id = Text1.Text
    MsgBox id
    Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
    Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID= & id & "
    Adodc2.Recordset.Requery
    Set DataGrid1.DataSource = Adodc2
    Adodc2.Recordset.Sort = "ID"
End Sub


Thanks.

Guna

This post has been edited by andrewsw: 22 June 2013 - 01:01 PM
Reason for edit:: Added code tags again

Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3181
  • View blog
  • Posts: 10,659
  • Joined: 12-December 12

Re: Data Grid Issue

Posted 22 June 2013 - 01:05 PM

@Guna Please wrap your code in code tags:

Quote

When you create your post, highlight the code and click the [ CODE ] button that appears just above where you are typing. Press the Preview Post button until it is correct.

Are you saying that the MsgBox displays 1 ?

Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID= & id & "

This code is incorrect. You are quoting the entire string. You need to split out the first part of the text, then the id, then the remaining text.

This was correct in your first post, why did you change it? If you, in fact, modified your code (or re-typed it) before making your first post, then this should inform you why this is NOT a good idea.

This post has been edited by andrewsw: 22 June 2013 - 01:08 PM

Was This Post Helpful? 0
  • +
  • -

#8 gunapriyan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 16-September 12

Re: Data Grid Issue

Posted 23 June 2013 - 12:05 AM

Friend,

Again I had to change the first post code....like,

  Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID='" & id & "'" 


But no changes.....But msgbox displays "1"....

I am confused...Please advise me.

Thanks & Regards,

Guna
Was This Post Helpful? 0
  • +
  • -

#9 gunapriyan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 16-September 12

Re: Data Grid Issue

Posted 23 June 2013 - 12:25 AM

Friends,

I had changed the code like as follows;

Private Sub Form_Load()
Dim id As String
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from table1"
id = Adodc1.Recordset(0)
MsgBox id
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID='" & id & "'"
Set DataGrid1.DataSource = Adodc2
Adodc2.Recordset.Sort = "ID"
End Sub




No changes...This is for your information.

Thanks & Regards,

Guna
Was This Post Helpful? 0
  • +
  • -

#10 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: Data Grid Issue

Posted 23 June 2013 - 12:58 AM

View Postgunapriyan, on 23 June 2013 - 12:25 AM, said:

Friends,

I had changed the code like as follows;

Private Sub Form_Load()
Dim id As String
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from table1"
id = Adodc1.Recordset(0)
MsgBox id
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID='" & id & "'"
Set DataGrid1.DataSource = Adodc2
Adodc2.Recordset.Sort = "ID"
End Sub




No changes...This is for your information.

Thanks & Regards,

Guna

still showing data of other ID's too ?
Was This Post Helpful? 0
  • +
  • -

#11 gunapriyan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 16-September 12

Re: Data Grid Issue

Posted 23 June 2013 - 04:45 AM

Yes...

What can i do?

Thanks & Regards,

Guna
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3181
  • View blog
  • Posts: 10,659
  • Joined: 12-December 12

Re: Data Grid Issue

Posted 23 June 2013 - 05:05 AM

Some basic debugging required. Change:

Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID='" & id & "'"
' to (temporarily)..
Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID='1'"
' then try..
Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID=1"

Adodc2.RecordSource = "SELECT * FROM TABLE2"

Use a MsgBox to display the RecordCount;
Delete the .Sort line at the bottom, pro-tem.

Learn to use the debugging features of the IDE.
Was This Post Helpful? 0
  • +
  • -

#13 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: Data Grid Issue

Posted 23 June 2013 - 05:51 AM

View Postandrewsw, on 23 June 2013 - 05:05 AM, said:

Some basic debugging required. Change:

Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID='" & id & "'"
' to (temporarily)..
Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID='1'"
' then try..
Adodc2.RecordSource = "SELECT * FROM TABLE2 where ID=1"

Adodc2.RecordSource = "SELECT * FROM TABLE2"

Use a MsgBox to display the RecordCount;
Delete the .Sort line at the bottom, pro-tem.

Learn to use the debugging features of the IDE.

hope so this will work . problem is in variable declared ID and using in where part of query
Was This Post Helpful? 0
  • +
  • -

#14 gunapriyan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 16-September 12

Re: Data Grid Issue

Posted 23 June 2013 - 11:54 AM

Dear Friends,

Finally I had achieved.

1. Change the Data Grid Properties from adcmdtable to adcmdtext
2.
  Adodc2.RecordSource = "SELECT * FROM TABLE2 where Emp_ID='" & CStr(id1) & "'"


Thanks for your all efforts.

Regards,

Guna
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1