V
VM
What's the fastest way to insert data into an Access table? I'm currently
using ExecuteNonQuery but it seems to take too long (should filling an mdb
table be slower than filling a datatable?). So this is my code to insert
several rows:
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Application.StartupPath + \\ZMData\\audit.mdb;
OleDbCommand myCommInsert = new OleDbCommand();
myCommInsert.Connection = new OleDbConnection(strDSN);
myCommInsert.Connection.Open();
sAuditRecord = sr.ReadLine(); /* First record in AZM Audit file to display
in datagrid */
while (sAuditRecord != null)
{
sQueryInsert = "";
sQueryInsert = "insert into audit ([col_row], [col_key], [col_Ref],
[col_input], [col_output], [col_notes], [col_action], [col_comments]," +
"[col_comments1], [col_comments2], [col_mark], [col_accept], [col_edit],
[col_reject], [col_default], [col_users])" +
"values ('" + sLine + "','" + sKey + "','" + sRefAddress + "','" +
sOldAddress + "','" + sOutAddress + "','" + sOutNotes + "','" +
sActionText + "','" + ZMNoteTxt + "','" + ZMNote1 + "','" + ZMNote2 +
"','" + sMark + "','" + sAccept + "','" + sEdit + "','" +
sReject + "','" + sDefault + "','" + sUsers + "')";
StreamWriter sw = new StreamWriter ("c:\\sql.txt");
sw.WriteLine(sQueryInsert);
sw.Close();
myCommInsert.CommandText = sQueryInsert;
myCommInsert.ExecuteNonQuery();
}
Thanks for your help
using ExecuteNonQuery but it seems to take too long (should filling an mdb
table be slower than filling a datatable?). So this is my code to insert
several rows:
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Application.StartupPath + \\ZMData\\audit.mdb;
OleDbCommand myCommInsert = new OleDbCommand();
myCommInsert.Connection = new OleDbConnection(strDSN);
myCommInsert.Connection.Open();
sAuditRecord = sr.ReadLine(); /* First record in AZM Audit file to display
in datagrid */
while (sAuditRecord != null)
{
sQueryInsert = "";
sQueryInsert = "insert into audit ([col_row], [col_key], [col_Ref],
[col_input], [col_output], [col_notes], [col_action], [col_comments]," +
"[col_comments1], [col_comments2], [col_mark], [col_accept], [col_edit],
[col_reject], [col_default], [col_users])" +
"values ('" + sLine + "','" + sKey + "','" + sRefAddress + "','" +
sOldAddress + "','" + sOutAddress + "','" + sOutNotes + "','" +
sActionText + "','" + ZMNoteTxt + "','" + ZMNote1 + "','" + ZMNote2 +
"','" + sMark + "','" + sAccept + "','" + sEdit + "','" +
sReject + "','" + sDefault + "','" + sUsers + "')";
StreamWriter sw = new StreamWriter ("c:\\sql.txt");
sw.WriteLine(sQueryInsert);
sw.Close();
myCommInsert.CommandText = sQueryInsert;
myCommInsert.ExecuteNonQuery();
}
Thanks for your help