473,545 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

INSERT statement with c# variables

1 New Member
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!
Apr 3 '08 #1
2 2829
jeffstl
432 Recognized Expert Contributor
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

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 Recognized Expert Specialist
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
5617
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 first name, last name, email, etc. The data are then sent to a PHP script (reg.php). The data are then inserted into a table (reg) in MS SQL server....
2
2409
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 this Insert into article values(now(), now(),....)
1
8731
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware tblSoftware ------------------- ------------------ ---------------------- PID PName PID* SID* SID SWName --- ...
2
35823
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 for the VALUES section are assigned before this sql statement. The problem occures with the payamt varable. It is a currency
3
1911
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? E.G. 2 Entites/Tables, tblA and tblB. Both have the same Attributes/fields 'Fname' and 'Lname. So my SQL statement looks like this:- "INSERT...
1
1878
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, drawnby, drawnbytime, doctor, dob, location, type-r-h, donortype-r-h, componet, antibody, unitnum, expdate, coombs, crossmatch, rhogam, unitnumber2,...
11
16201
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, Col3, Col4) Values(" & _ str1 & "," & dt1 & "," & str2 & "," & str3 & ")" where str1 = "col1"
2
3191
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 with the javascript im using but i can print the correct values so why am i unable to use them to enter data to a database? sorry i am new to all this...
2
30115
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 through the recordset (based on a linked spreadsheet, 'tbl_group_import') and using the INSERT INTO statement on each loop. I am using the...
1
2502
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 '<'. /int_code04/myNMLC/insertNewTrackRecord.asp, line 97 I've tested the INSERT stmt both within SQL Server and as a string literal within the page's code...
0
7484
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7928
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7440
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7775
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5997
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4963
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1902
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
726
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.