Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Search query using search term from user input into TextBox

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

Comments

  • dokken2dokken2 Member Posts: 532
    : 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 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
    :
    :


    your problem is in the where clause-

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

    need to put the 'value' of the textbox in the statement, not the literal string of 'textbox1'

    SELECT...
    FROM...
    WHERE mycolumn = '" & TextBox1.Text & "'"
Sign In or Register to comment.