Please help with Prepared statements and c#
611395Apr 3 2008 — edited Apr 3 2008i 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