Cryptic SQL Error 8178?

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

Guest

Prepared statement '(@KeyNo int, @Key sql_variant) SELECT KeyNo, Key' expects
parameter @KeyNo, which was not supplied.

The following code snippet gives me the above error, what the heck does this
error mean? @KeyNo was supplied, what is it asking for?

SqlCommand mySelectCmd = new SqlCommand();
mySelectCmd.Connection = myConn;
mySelectCmd.Parameters.Add("@KeyNo", SqlDbType.Int, 10, "KeyNo");
mySelectCmd.Parameters.Add("@Key", SqlDbType.Variant, 255, "Key");
mySelectCmd.CommandText = "SELECT KeyNo, Key FROM KeyTable ";
SqlDataAdapter myDA = new SqlDataAdapter();
DataSet myDS = new DataSet();
myDA.SelectCommand = mySelectCmd;
myDA.Fill(myDS,"KeyTable");
 
Nothing cryptic about it. You need to supply a value for the two parameters,
not merely a name. It is easier to see where the error is if you create the
parameters separate from adding them to the select query.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top