Hello,
There is no need to have a list of
OleDBCommand
.
IDbCommand
infact is used when your SQL is static and only data values are changing e.g. Insert 1000 emplouees. This way database does not have to recompile the SQL each time and there by getting improved performance in such operations.
Basically to your function you will pass a List<t> of object whose property values are to be inserted in the database. Then inside function create a
oleDBCommand
object and add parameters (in your case 16). Write a for loop around List<t> and inside loop assign value to each parameter and execute the query. Your code should look something like shown below.
for (Employee obj in lstData) {
cmd.parameters[0].value = obj.endDate ?? (object)DBNull.Value;
cmd.parameters[1].value = obj.startDate ?? (object)DBNull.Value;
...
cmd.parameters[15].value = obj.desc ?? (object) DBNull.Value;
cmd.ExecuteNonQuery();
if ((messagesSent % commitEveryNo == 0) && (messagesSent != 0)) {
tran.Commit();
tran.Dispose();
tran = null;
tran = conn.BeginTransaction();
}
messagesSent++;
}
let me know if it helpes.
Regards,