I’ve not used basic SQL commands for a while and I’m trying to pass a param to a sproc and the run it. However when I run the code I get a “Not Supplied” error.
Code:
SqlConnection conn1 = new SqlConnection(DAL.getConnectionStr());
SqlCommand cmd1 = new SqlCommand("SProc_Item_GetByID", conn1);
cmd1.Parameters.Add(new SqlParameter("@ID", itemId));
conn1.Open();
cmd1.ExecuteNonQuery();
I’m not really sure why this would fail. Apologies for the basic question, but I’m lost!
Thanks in advance.
You should set the
CommandTypetoStoredProcedure, set the connection and useParameters.AddWithValue("@ID", itemID)If you want to use
Parameters.Add()(which is obsolete), here is how you do it (you need to pass the type too)This should work: