Results 1 to 8 of 8

Thread: Ado sql selection and display to grid

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    51

    Post

    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..

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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).]

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    51

    Post

    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.

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    de nada! Me gusto ayudar con Visual Basic

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    51

    Post

    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...

  7. #7
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    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



  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    51

    Post

    Clunietp,

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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width