INSERT statement with c# variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • btuisee
    New Member
    • Apr 2008
    • 1

    INSERT statement with c# variables

    I'm having an issue getting a variable to pass through to an oracle database. I have an insert statment and one of the values are a variable called q1. Q1 is a variable that gets it's value from a radiolistbuton. I can't get the variable to pass through and insert into the db. It's an oracle 10g express db and the insert statement works when a normal string is netered but not with a variable and ideas?

    OracleTransacti on txn = conn.BeginTrans action();
    OracleCommand cmd = conn.CreateComm and();
    cmd.CommandText = "insert into test(test) values (&q1)";
    cmd.ExecuteNonQ uery();
    txn.Commit();


    Thanks for any insight available!
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    Originally posted by btuisee
    I'm having an issue getting a variable to pass through to an oracle database. I have an insert statment and one of the values are a variable called q1. Q1 is a variable that gets it's value from a radiolistbuton. I can't get the variable to pass through and insert into the db. It's an oracle 10g express db and the insert statement works when a normal string is netered but not with a variable and ideas?

    OracleTransacti on txn = conn.BeginTrans action();
    OracleCommand cmd = conn.CreateComm and();
    cmd.CommandText = "insert into test(test) values (&q1)";
    cmd.ExecuteNonQ uery();
    txn.Commit();


    Thanks for any insight available!
    This might be something you've checked but since you didn't say I have to ask first, what is the value of q1 prior to the execution of the query?

    If its null, that might be the issue.

    Another possible thing you might have checked , is checking for the SelectedIndex property is not a -1

    [code=vbnet]
    If ButtonList.Sele ctedIndex <> -1 Then
    MyVar1 = ButtonList.Sele ctedItem.Text
    MyVar2 = ButtonList.Sele ctedItem.Value
    End If

    [/code]

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      this line:
      Code:
      cmd.CommandText = "insert into test(test) values (&q1)";
      is not sending variables. It should be more like this (I'm not writing in c#, but I hope you get the picture)
      Code:
      cmd.CommandText = "insert into test(" & test & ") values (" & q1 & ")"
      By the way, you can not write ASP in C#. Did you intend to say ASP.NET (aspx)?

      Jared

      Comment

      Working...