?
Solved

Insert into Oracle using parameters with OracleClient

Posted on 2006-10-22
1
Medium Priority
?
882 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 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