Solved

Insert into Oracle using parameters with OracleClient

Posted on 2006-10-22
1
878 Views
Last Modified: 2012-05-05
The following code works, but I need to use a parameter for city because I am looping through a list.
            
OracleConnection conn = new OracleConnection(connectionString);
OracleCommand command = conn.CreateCommand();
OracleTransaction transaction;
conn.Open();
transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted);
command.Transaction = transaction;
command.CommandText =
"INSERT INTO address (city) values ('test')";
command.ExecuteNonQuery();
transaction.Commit();
conn.Close();

Thanks!
0
Comment
Question by:vandy02
1 Comment
 
LVL 8

Accepted Solution

by:
Rytmis earned 250 total points
ID: 17784504
// Use a named parameter "city" in the query
command.CommandText = "INSERT INTO address (city) values (:city)";

// Create a new OracleParameter object, bound to a named parameter called "city"
OracleParameter param = new OracleParameter("city", OracleType.Varchar2);

// Set the value for the parameter
param.Value = "Test";

// Add the parameter to the command's parameter collection
command.Parameters.Add(param);

Before you re-use the same command, call:

command.Parameters.Clear();

to make sure you don't accidentally re-use the old parameters as well.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question