Im having a problem with "like operator" on SQL database

Im using this code to search on database

    Dim DV As New DataView(dbDataSet)
        DV.RowFilter = String.Format("ID Like '%{0}%'", TextBox1.Text)
        DataGridView1.DataSource = DV

and at textbox1 I type 2
in data grid view show all people who have number 2 at their ID

how to make it search EXACTLY the some id as the textbox ?

Recommended Answers

All 4 Replies

How about

DV.RowFilter = "ID = " & TextBox1.Text

after did like that
it show this problem

"An unhandled exception of type 'System.Data.SyntaxErrorException' occurred in System.Data.dll

Additional information: Syntax error: Missing operand after '=' operator."

this is the code

Dim DV As New DataView(dbDataSet)
        DV.RowFilter = "ID = " & TextBox1.Text
        DataGridView1.DataSource = DV

What data type is ID in your database?

Can you debug your code, copy and paste the SQL statement and execute it directly against the database - in SQL Management Studio for example - and see what happens. This will give you a much clearer idea of what may be wrong.

the code work, well. found an other idea(a bit more complicated) to correct the mistake

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.