Search query using search term from user input into TextBox

Discussion in 'Visual Basic ( VB )' started by Mendoza, Jul 27, 2007.

  1. Mendoza

    Mendoza New Member

    Joined:
    Jul 27, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi everyone, thank you for the help you provide on this forum, I've learned a lot so far.

    Right now I'm making a simple Access-Visual Basic 2005 .NET database. I want to make a Search Query that will search the Database for text similar to what the user inputs into TextBox1.Text on the form where the datagrid is displayed.

    I've created a query that works if:

    SELECT...
    FROM...
    WHERE mycolumn = 'oxygen'

    for example. It will retrieve and display all matches for oxygen, so the query itself works. But it does not work with the variations I have tried on:

    SELECT...
    FROM...
    WHERE mycolumn = ' "TextBox1.Text" '

    The query is:

    SELECT FirstName, LastName, City, Major, StudentID FROM Students
    WHERE FirstName LIKE ...

    I want to be able to search the column <FirstName> for the text that the user inputs in TextBox1.Text and then display the parts of the datagrid that match that.

    A blank datagrid appears. I don't think the query is able to see what TextBox1.Text contains.

    What do you recommend I do to make this work? Or what alternatives exist to making a robust search button with search terms?

    Thanks,

    Mendoza
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Print the Query just before executing and see what is the value of the query string.
     
  3. Mendoza

    Mendoza New Member

    Joined:
    Jul 27, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    The code is now:

    Code:
    Dim connection As New OleDbConnection
    
    ("Provider=Microsoft.Jet.OLEDB.4.0;Source=C:\MSDS\MSDS DATABASE DATA\MSDS.mdb;")
    
    Dim [command] As New OleDbCommand("SELECT * FROM Students WHERE FirstName LIKE ?", connection)
    
    [command].Parameters.AddWithValue("@FirstName", Me.TextBox1.Text & "%")
    
            [U]connection.Open()[/U]
    
            Dim rdr As OleDbDataReader = command.ExecuteReader()
    
            Dim tbl As New DataTable()
            tbl.Load(rdr)
            Me.StudentsDataGridView.DataSource = tbl
    
            rdr.Close()
            connection.Close()
    And there is a crash due to connection.Open() stating: Could not find installable ISAM.

    I tried to fix the problem through this:

    http://support.microsoft.com/kb/209805

    But all registry references were correct and files were found.



    EDIT: Probably has something to do with the fact that I don't have Microsoft Access installed. Tho that hasn't stopped me up to this point.
     
    Last edited by a moderator: Jul 31, 2007
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You don't need the MS Access but you need the Database Engine to establish the connection.
     
  5. rosewitter

    rosewitter New Member

    Joined:
    Jul 28, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    :thinking:
    How can I get the data into a text box (eg. Text1.Text) which is selected in a Datagrid1.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice