Solved

Insert into Oracle using parameters with OracleClient

Posted on 2006-10-22
1
881 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

717 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