Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Please help with Prepared statements and c#

611395Apr 3 2008 — edited Apr 3 2008
i have some test code here which im not sure is right, please lead me down the correct path.

OracleConnection con = OpenDBConnection();
OracleTransaction tr = con.BeginTransaction();
string SQLInsert = "INSERT INTO RHYS_TRY (SYMBOL_ID, TRADE_DATE,OPEN,HIGH,LOW,CLOSE) VALUES (:S_ID,:trade_date,:open,:high,:low,:close)";

for (int i = 0; i < 50; i++)
{
OracleCommand cmd = new OracleCommand(SQLInsert, con);
cmd.Parameters.Add("S_ID", 20.0);
cmd.Parameters.Add("trade_date", DateTime.Parse("2006-03-01"));
cmd.Parameters.Add("open", 20.0);
cmd.Parameters.Add("high", 20.0);
cmd.Parameters.Add("low", 20.0);
cmd.Parameters.Add("close", 20.0);
cmd.Prepare();
cmd.ExecuteNonQuery();
}
tr.Commit();


this code works but im not sure if this is how it should be done as i only want to change the parameters in the loop and not create the cmd agai.. or is this how it meant to be done? when ever i put the OracleCommand cmd = new OracleCommand(SQLInsert, con); out side the loop, it throws and error

Please help
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 1 2008
Added on Apr 3 2008
2 comments
892 views