C
C#13mo ago
u41c

✅ Stored Procedure Help

Hello, I have a stored procedure in my project called spGetVendor. It takes one parameter, @VendorID. I've instantiated a new SqlCommand object that can be used to interact with the stored procedure and I've passed the parameter to it. When I try to use it however, it says that the parameter has not been passed?? Any ideas?
public static Vendor GetVendor(int vendorID)
{
Vendor vendor = new Vendor();
SqlConnection connection = PayablesDB.GetConnection();
//string selectStatement =
// "SELECT VendorID, Name, Address1, Address2, City, State, " +
// "ZipCode, Phone, ContactFName, ContactLName, " +
// "DefaultAccountNo, DefaultTermsID " +
// "FROM Vendors " +
// "WHERE VendorID = @VendorID";
SqlCommand selectCommand = new SqlCommand("spGetVendor", connection);
selectCommand.Parameters.AddWithValue("@VendorID", vendorID);
public static Vendor GetVendor(int vendorID)
{
Vendor vendor = new Vendor();
SqlConnection connection = PayablesDB.GetConnection();
//string selectStatement =
// "SELECT VendorID, Name, Address1, Address2, City, State, " +
// "ZipCode, Phone, ContactFName, ContactLName, " +
// "DefaultAccountNo, DefaultTermsID " +
// "FROM Vendors " +
// "WHERE VendorID = @VendorID";
SqlCommand selectCommand = new SqlCommand("spGetVendor", connection);
selectCommand.Parameters.AddWithValue("@VendorID", vendorID);
3 Replies
Tvde1
Tvde113mo ago
what's the exact error you get?
u41c
u41cOP13mo ago
No description
u41c
u41cOP13mo ago
Nevermind, solution was to change the CommandType of the SqlCommand object to CommandType.StoredProcedure
Want results from more Discord servers?
Add your server