473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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 2821
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

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

Similar topics

2
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their...
2
by: Bob Bedford | last post by:
I've a query with insert records in a table. I've 2 fields: DateTimeInsertion and DateTimeLastModification. When I create the record, I must have those 2 fields set the same value. Now I've...
1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
2
by: Nothing | last post by:
I have a SQL statement that is not working. It reads as follows: sql = "INSERT INTO tblPaymentInformation (, , , , ) VALUES ('aucdte', 'bidnum', 'paytyp', 'paynum', payamt)" The variables...
3
by: Kelvin | last post by:
Is it possible when coding a SQL statement to use variables within an INSERT INTO statement i.e the variables contain some data I wish to insert along with the standard entity.attribute data? ...
1
by: Nothing | last post by:
I am trying to use the sql INSERT INTO statement to add a new record. This is the SQL statement: sql = "INSERT INTO tblpatients(bbid, patientname, orderdate, ordertime, mrnumber, sex, age,...
11
by: sm | last post by:
Hi All, Can anybody give me the syntax to insert a record into SQL server through VB code using variables? The following statement is failing! sInsertQuery = "INSERT INTO TestTab (Col1, Col2,...
2
by: adamace5o | last post by:
When i try to use post variables with php and mysql i can't get the insert into statement to accept varibles as values. If i use 'test' instead of $test it does work. I suspect it is something to do...
2
by: franc sutherland | last post by:
Hello, I am using Access 2003. Is it possible to use string variables in the INSERT INTO statement? I am using the INSERT INTO statement to add a long list of contacts to a group by looping...
1
by: Maklar60 | last post by:
I am attempting to execute an INSERT statement on my page but continually get the following error: Microsoft OLE DB Provider for ODBC Drivers error '80040e14' Incorrect syntax near '<'. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.