Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the code I have:
VB
Dim mySqlCommand As New SqlCommand()
Dim mySqlDataAdapter As New SqlDataAdapter()
mySqlCommand.CommandText = myCommandText
mySqlCommand.Connection = SecurityRolesConnection
mySqlCommand.Parameters.Add("@EmployeeID", SqlDbType.BigInt)
Long.TryParse(idTextBox.Text, myBigInt)
mySqlCommand.Parameters("@EmployeeID").Value = myBigInt
mySqlCommand.Prepare()
mySqlDataAdapter.SelectCommand = mySqlCommand
mySqlDataAdapter.Fill(myDataSet)
myTableView = myDataSet.Tables(0).DefaultView

The program fails at the "mySqlDataAdapter.Fill(myDataSet)" statement with this error message:
"Procedure or function 'AllSecurityRolesAndSelected' expects parameter '@EmployeeID', which was not supplied."
When I change the StoredProcedure to not look for this parameter, and hard code a valid EmployeeID into the StoredProcedure, and change the VB code to not try to pass a parameter, the StoredProcedure and VB are able to communicate, and the DataGrid on my form fills with the correct data.
I just have no idea why this code is not working to actually add the @EmployeeID parameter to the SqlCommand.
Any help with what I need to do would be greatly appreciated.
Posted

What is your commandtext? Is it a query, or is it a stored procedure name? If you're trying to used a stored procedure, you have to explicity set the CommandType property to CommandType.StoredProcedure.
 
Share this answer
 
Please share your stored..procedure, and check your sp parameter is matching with the one you are passing
 
Share this answer
 
John, Thank you! Interesting this worked with no parameters, but my command text (sorry I missed having it in my original post) was "Execute AllSecurityRolesAndSelected".
After setting the CommandType property to CommandType.StoredProcedure, I took the Execute out, and now it works!
Again, thank you!
Vic
 
Share this answer
 

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