Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   exception raised for valid variable declaration? (http://www.velocityreviews.com/forums/t96934-exception-raised-for-valid-variable-declaration.html)

Carlos 02-17-2005 08:14 PM

exception raised for valid variable declaration?
 


Hi all,

I do get the following exception when trying to create a new data row in

one of my tables:

System.Data.SqlClient.SqlException: Must declare the variable '@cAttend'

I have the following code:, which deckares the variable within the scope of
the

execution, so I am kind of confused why this happens. Any help is
appreciated

Thanks,

Carlos.



{

char cAttend = 'N';

this.sqlInsertCommand1.CommandText = "INSERT INTO mytable (keyNum,
cAttended) VALUES (131415, @cAttend)";

sqlInsertCommand1.ExecuteNonQuery();

}





Wilco Bauwer 02-17-2005 08:26 PM

Re: exception raised for valid variable declaration?
 
Lookup any article about "parameterized queries". Basically you are
declaring a variable (or: "placeholder"), but you aren't filling the
placeholder. You should add somethin like
this.sqlInsertCommand1.Parameters.Add("@cAttend", myValue); before you
actually execute the query.



All times are GMT. The time now is 01:33 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.