S
SteveK
I'm making a stored procedure for an Access DB and I'm adding
OleDbParameter objects to the OleDbCommand object. This all makes sense and
seems fine. However, for some reason when inserting thousands of records
using a loop, the values being inserted to the tables are the same for every
record inserted.
I have verified that I am setting the OleDbParamter.Value property correctly
for each respective insert, but still it is using a constant value. Here is
the code:
public void InsertRecords(ArrayList list)
{
string sql = string.Empty;
OleDbCommand cmd = new OleDbCommand();
OpenConn();
cmd.Connection = m_conn;
OleDbParameter param = new OleDbParameter("paramID",
OleDbType.Integer, 4, "shotID");
cmd.Parameters.Add(param);
param = new OleDbParameter("paramName", OleDbType.VarChar, 128,
"Name");
cmd.Parameters.Add(param);
param = new OleDbParameter("paramShotNr", OleDbType.TinyInt, 1,
"TakeNr");
cmd.Parameters.Add(param);
param = new OleDbParameter("paramDescription", OleDbType.VarChar,
1024, "Description");
cmd.Parameters.Add(param);
// loop through and insert each one creating dependent records as
needed...
foreach(object o in list)
{
ShotRecord shot = (ShotRecord)o;
cmd.Parameters[0].Value = shot.ID; // ID
cmd.Parameters[1].Value = shot.takeName; // Name
cmd.Parameters[2].Value = shot.takeNum; // Take Nr
cmd.Parameters[3].Value = shot.description; //
Description
sql = "EXECUTE sp_InsertTest";
cmd.CommandText = sql;
try
{
cmd.ExecuteNonQuery();
}
catch(OleDbException e)
{
m_ui.ShowMessage(string.Format("DAL ERROR
OCCURED!\n\nException Text:\n{0}", e.Message), "DAL ERROR");
}
}
CloseConn();
}
What have I done wrong? This is very odd behavior, has anyone else seen
this??
Thanks,
Steve
OleDbParameter objects to the OleDbCommand object. This all makes sense and
seems fine. However, for some reason when inserting thousands of records
using a loop, the values being inserted to the tables are the same for every
record inserted.
I have verified that I am setting the OleDbParamter.Value property correctly
for each respective insert, but still it is using a constant value. Here is
the code:
public void InsertRecords(ArrayList list)
{
string sql = string.Empty;
OleDbCommand cmd = new OleDbCommand();
OpenConn();
cmd.Connection = m_conn;
OleDbParameter param = new OleDbParameter("paramID",
OleDbType.Integer, 4, "shotID");
cmd.Parameters.Add(param);
param = new OleDbParameter("paramName", OleDbType.VarChar, 128,
"Name");
cmd.Parameters.Add(param);
param = new OleDbParameter("paramShotNr", OleDbType.TinyInt, 1,
"TakeNr");
cmd.Parameters.Add(param);
param = new OleDbParameter("paramDescription", OleDbType.VarChar,
1024, "Description");
cmd.Parameters.Add(param);
// loop through and insert each one creating dependent records as
needed...
foreach(object o in list)
{
ShotRecord shot = (ShotRecord)o;
cmd.Parameters[0].Value = shot.ID; // ID
cmd.Parameters[1].Value = shot.takeName; // Name
cmd.Parameters[2].Value = shot.takeNum; // Take Nr
cmd.Parameters[3].Value = shot.description; //
Description
sql = "EXECUTE sp_InsertTest";
cmd.CommandText = sql;
try
{
cmd.ExecuteNonQuery();
}
catch(OleDbException e)
{
m_ui.ShowMessage(string.Format("DAL ERROR
OCCURED!\n\nException Text:\n{0}", e.Message), "DAL ERROR");
}
}
CloseConn();
}
What have I done wrong? This is very odd behavior, has anyone else seen
this??
Thanks,
Steve