Arash
Arash

Reputation: 3051

Get All Of The Rows Like Input Text In TextBox

i have a textbox and i want to find all of the words begin with the letter in textbox(for example a)

i know i should use

 "select * from tbl_search where Name like a% "

but it doesnt work for values in textbox.for example i wrote like this:

        cmd = New SqlCommand("select * from tbl_search where Name like @value%") 'it gives the runtime error :"Incorrect syntax near '%'."
        cmd.Parameters.AddWithValue("@value", TextBox1.Text)

Upvotes: 0

Views: 585

Answers (2)

NaveenBhat
NaveenBhat

Reputation: 3318

You need to write the command like this(need to add + between @value and '%'):

    cmd = New SqlCommand("select * from tbl_search where Name like @value + '%'")
    cmd.Parameters.AddWithValue("@value", TextBox1.Text)

Upvotes: 2

Polynomial
Polynomial

Reputation: 28316

You need to enclose your value in quotes:

cmd = New SqlCommand("select * fromt tbl_search where Name like ""@value%""");

VB.NET escapes double quotes to one quote, so that you can put a " character in your strings.

Upvotes: 0

Related Questions