exception raised for valid variable declaration?

Discussion in 'ASP .Net' started by Carlos, Feb 17, 2005.

  1. Carlos

    Carlos Guest

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

    }
     
    Carlos, Feb 17, 2005
    #1
    1. Advertising

  2. Carlos

    Wilco Bauwer Guest

    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.
     
    Wilco Bauwer, Feb 17, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SklNLkgu?=

    : an exception raised

    =?Utf-8?B?SklNLkgu?=, Mar 2, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    441
    =?Utf-8?B?SGl0ZXNo?=
    Jun 3, 2005
  2. Lonnie Princehouse
    Replies:
    8
    Views:
    540
    Lonnie Princehouse
    Oct 2, 2004
  3. Kannan
    Replies:
    21
    Views:
    878
  4. Bolin
    Replies:
    4
    Views:
    412
  5. Angus
    Replies:
    16
    Views:
    499
    Chris ( Val )
    Sep 29, 2007
Loading...

Share This Page