Click here to Skip to main content
14,825,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use the following query
Dim sqlQry As String = "SELECT * FROM tblTest where Name=@NM and Rank=@RN"
Then I fill my dataadapter by
Dim dAdt As New SqlDataAdapter(sqlQry, conStr)

But donot know where to put the parameters that I have set after where clause.

Updated 6-Sep-11 5:41am

Instead of passing the SQL string to the adapter create a SqlCommand[^], define the SqlParameters[^] and use that command for your adapter. When doing this you also have to create the SqlConnection.

So something like:
Dim databaseConnection As New SqlConnection
Dim queryCommand As New SqlCommand

databaseConnection.ConnectionString = conStr
queryCommand.CommandText = "SELECT * FROM tblTest where Name=@NM and Rank=@RN"
queryCommand.Parameters.AddWithValue("@NM", someNMvariable)
queryCommand.Parameters.AddWithValue("@RN", someRNvariable)
queryCommand.Connection = databaseConnection
Dim dAdt As New SqlDataAdapter(queryCommand)
Sander Rossel 6-Sep-11 13:49pm
My 5 for the correct and clear answer, except of course select * is quite a coding horror... :)
Wendelius 6-Sep-11 14:44pm
Thanks. Yep, that's a real horror :)

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

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