Help needed with Parameters/SQL Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I am new to this game.

I am trying to compile an applicaiton with an sql database.

I have a form and have linked to a certain table and the correct fields
display the correct values.

I have then added a combo box onto the form, would like to click a certain
persons name, and then it would display there information on the form. I
have followed some of microsoft walkthrough's - but after puttng in a try
catch - the error is saying:

Prepared statement '"@user_nameparam nvarchar(255)) SELECT employeeID,
User_Name, log' expects parameter @user_nameparam, which was not supplied

Any help greatly appreciated
 
If you Import the System.Data.SqlClient namespace you won't have to fully
qualify the types the way I did. Hope it helps.
Jared

Dim conn As New
System.Data.SqlClient.SqlConnection("Server=YourServerName;Database=YourDBName;Trusted_Connection=True;")
Dim cmd As New System.Data.SqlClient.SqlCommand("SELECT * FROM Customers
WHERE CustomerID=@CustomerID", conn)
cmd.Parameters.Add("@CustomerID", SqlDbType.VarChar)
cmd.Parameters("@CustomerID").Value = "Some_Value_You_Set"
Try
conn.Open()
Dim Reader As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader
'Do something with the reader here.
Catch sqlex As SqlClient.SqlException
'code to process sql errors
Catch ex As Exception
'code to process other errors
Finally
conn.Close()
End Try
 
Paul,
You would get more help if you posted the code block in question. It's
hard to troubleshoot a an exception when you have no code to accompany it.
Jared
 
Back
Top