PDA

Click to See Complete Forum and Search --> : Ado sql selection and display to grid


ptran
Jan 18th, 2000, 09:07 PM
Can any help me out with an example how to display a select text from text box, and display the result to a grid with a sql query. I can easier do this in MS-Access, but find it differcult with VB ADO.

Thanks..

Clunietp
Jan 19th, 2000, 12:53 PM
http://www.vb-world.net/ubb/Forum3/HTML/002669.html

This post uses SQL server, just change the connection string to your Access DB and the rest should work fine

Tom

[This message has been edited by Clunietp (edited 01-20-2000).]

ptran
Jan 19th, 2000, 09:30 PM
Clunietp,

Thanks for the help, I got it to connect and display the data in to the grid with the whole data. However I want to customer my Sql statement to display only the select data, I got and error, here is my code:

Set cn = New Connection
cn.Open "provider=Microsoft.jet.OLEDB.4.0;" & "Persist Security Info=FALSE;" & "Data Source = C:\12_13_99.mdb"
rs.Open "SELECT TestTable.* From TestTable where "combo1.Text" = "text1.Text" order BY LATA, `LERG 6_NPA`, `lerg 6_nxx`"
End Sub

Combo1.text is select from combo list
text1.text is text from text box.
Did I code it right or I missed something?

Thanks.

Clunietp
Jan 19th, 2000, 10:35 PM
change this:

SELECT TestTable.* From TestTable where "combo1.Text" = "text1.Text" order BY

to this:

SELECT TestTable.* From TestTable where MyFieldNameToSearch = '" & text1.Text & "' order BY...


Tom

Clunietp
Jan 20th, 2000, 10:31 AM
de nada! Me gusto ayudar con Visual Basic :)

ptran
Jan 20th, 2000, 11:11 AM
Clunietp,

Is there anyway we can pass the field from combo1 list to MyFieldNameToSearch.

ex. instead of
SELECT TestTable.* From TestTable where MyFieldNameToSearch = '" & text1.Text & "' order BY..

MyfieldNameToSearch is pass on by combo text?

Just wondering...

Clunietp
Jan 20th, 2000, 11:27 AM
You can concatenate any string you would like.

SELECT TestTable.* From TestTable where [" & combo1.text & "] = '" & text1.Text & "' order BY...

I added the brackets [] in case your table name had spaces in it....

Tom

ptran
Jan 20th, 2000, 11:38 AM
Clunietp,

thank for all you help. Don't know what to do without. Once again...mucho garcias!

:)