Reputation: 93
I have another issue...here is the code
public int CheckForDuplicateRandomOrderNumber()
{
int randomNumber = GenerateRandomOrderNumber();
string strCmdCheckForDuplicates = "sp_Check$For$Duplicate$Order$Numbers";
SqlCommand cm = new SqlCommand(strCmdCheckForDuplicates, cn);
SqlParameter myPm;
myPm = cm.Parameters.Add("@OrderNumber", SqlDbType.Int);
myPm.Value = randomNumber;
myPm.Direction = ParameterDirection.Input;
cn.Open();
cm.ExecuteReader();
cn.Close();
if (randomNumber == 1)
{
return randomNumber;
}
else
return 0;
}
When I run this code I get an error saying the stored procedure is expecting a parameter to be passed and when I debug the variable has the parameter being passed. I have no idea why this is happening... and another question that relates to this... when I write this...
cm.parameters.add(new sqlparameter("@OrderNumber", sqldbtype.int)).value = randomNumber;
there is no parameter direction
Upvotes: 1
Views: 100
Reputation: 93
I found out what the issue was with my code...I forgot one line, one little line of code...
cm.CommandType = CommandType.StoredProcedure;
Its no wonder why it kept saying I wasn't supplying the parameter, it didn't know what I was doing...I guess this is a classic moment that goes to show how one missed line of code can cause hours of time trying to figure it out.
Upvotes: 2
Reputation: 643
First I would check that randomnumber is not null, if it is it will look like the parameter is missing.
Upvotes: 0