exception raised for valid variable declaration?

C

Carlos

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();

}
 
W

Wilco Bauwer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top