Click here to Skip to main content
15,071,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I get this error while I am trying to execute a parameter from a custom select statment.
In a button click
VB
Me.SqlDataAdapter1.SelectCommand.CommandText = SELECT * FROM Table_1 WHERE surname LIKE +'%'+@sur+'%'
              Me.SqlDataAdapter1.SelectCommand.Parameters(0).Value = TextBox1.Text

And I get this error when I am trying to fill the dataadapter, it works only when I insert a predefined value in the dataadapter designer (I didn't create the adapter through code.

Thank you
Kyriakos
Posted
Updated 10-Mar-11 23:53pm
v2

Do not include parameters between strings. Include the % op within the param.

Me.SqlDataAdapter1.SelectCommand.CommandText = "SELECT * FROM Table_1 WHERE surname LIKE @sur"

Me.SqlDataAdapter1.SelectCommand.Parameters(0).Value = "%" & TextBox1.Text & "%"


--Edit--
If an error occurs, you may not have added the parameter. Try adding the parameter

SQL
Me.SqlDataAdapter1.SelectCommand.Parameters.AddWithValue("@sur", TextBox1.Text)
   
v2
Had to convert to string was an int32.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900