Using variable in an insert statement

Discussion in 'ASP .Net' started by =?Utf-8?B?SnVzdGlu?=, Nov 9, 2004.

  1. I have the following insert statement:

    "INSERT INTO Queue(CustomerId, Status, QueueId, Type, January) VALUES
    (@CustomerId" + ", @Status, @QueueId, @Type, @January); SELECT uId,
    CustomerId, Status, QueueId, " + "Type, January FROM Queue WHERE (uId =
    @@IDENTITY)";

    this.sqlInsertCommand1.Parameters.Add("@January",
    System.Data.SqlDbType.VarChar, 10, "January").Value =
    ItemQueue.Items.ToString();

    Where you see "January" I would like to pass a vaiable depending o the month
    selected.

    How can I accomplish this task?

    Thanks, Justin.
     
    =?Utf-8?B?SnVzdGlu?=, Nov 9, 2004
    #1
    1. Advertising

  2. You should use ADO.NET parameter objects. In addition to solving your
    problem they will protect you against SQL Injection Attacks.

    Here's more info:
    http://msdn.microsoft.com/library/d...systemdatasqlclientsqlparameterclasstopic.asp
    http://msdn.microsoft.com/library/d...ngparameterizedstoredprocedurevisualbasic.asp

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net


    "Justin" <> wrote in message
    news:...
    >I have the following insert statement:
    >
    > "INSERT INTO Queue(CustomerId, Status, QueueId, Type, January) VALUES
    > (@CustomerId" + ", @Status, @QueueId, @Type, @January); SELECT uId,
    > CustomerId, Status, QueueId, " + "Type, January FROM Queue WHERE (uId =
    > @@IDENTITY)";
    >
    > this.sqlInsertCommand1.Parameters.Add("@January",
    > System.Data.SqlDbType.VarChar, 10, "January").Value =
    > ItemQueue.Items.ToString();
    >
    > Where you see "January" I would like to pass a vaiable depending o the
    > month
    > selected.
    >
    > How can I accomplish this task?
    >
    > Thanks, Justin.
     
    Steve C. Orr [MVP, MCSD], Nov 9, 2004
    #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. Replies:
    2
    Views:
    622
    =?iso-8859-1?q?Stephan_Br=F6nnimann?=
    Jan 19, 2006
  2. Froefel
    Replies:
    1
    Views:
    803
    Mark Rae [MVP]
    Jul 4, 2007
  3. J. Muenchbourg
    Replies:
    3
    Views:
    259
    Aaron Bertrand - MVP
    Sep 30, 2003
  4. mvr
    Replies:
    2
    Views:
    167
  5. mvr
    Replies:
    0
    Views:
    92
Loading...

Share This Page