469,602 Members | 1,781 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

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?

OracleTransaction txn = conn.BeginTransaction();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into test(test) values (&q1)";
cmd.ExecuteNonQuery();
txn.Commit();


Thanks for any insight available!
Apr 3 '08 #1
2 2684
jeffstl
432 Expert 256MB
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?

OracleTransaction txn = conn.BeginTransaction();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into test(test) values (&q1)";
cmd.ExecuteNonQuery();
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

Expand|Select|Wrap|Line Numbers
  1.   If ButtonList.SelectedIndex <> -1 Then
  2.     MyVar1 = ButtonList.SelectedItem.Text
  3.     MyVar2 = ButtonList.SelectedItem.Value
  4.   End If
  5.  
  6.  
Apr 4 '08 #2
jhardman
3,406 Expert 2GB
this line:
Expand|Select|Wrap|Line Numbers
  1. 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)
Expand|Select|Wrap|Line Numbers
  1. 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
Apr 7 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by newbie_mw | last post: by
2 posts views Thread by Bob Bedford | last post: by
2 posts views Thread by Nothing | last post: by
3 posts views Thread by Kelvin | last post: by
1 post views Thread by Nothing | last post: by
2 posts views Thread by franc sutherland | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.