Solved

Insert into Oracle using parameters with OracleClient

Posted on 2006-10-22
1
875 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
Comment Utility
// 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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 video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now