Reputation: 10236
I have been following the code from Bulk Insert However I am getting an exception of Invalid Argument at AccesssRecordset.Update(); or rs.Update();
It takes two arguments Int UpdateType and bool Force
public void BulkExportToAccess(DataTable dtOutData, String DBPath, String TableNm)
{
DAO.DBEngine dbEngine = new DAO.DBEngine();
Boolean CheckFl = false;
try
{
DAO.Database db = dbEngine.OpenDatabase(DBPath);
DAO.Recordset AccesssRecordset = db.OpenRecordset(TableNm);
DAO.Field[] AccesssFields = new DAO.Field[dtOutData.Rows.Count];
//Loop on each row of dtOutData
for (Int32 rowCounter = 0; rowCounter < dtOutData.Rows.Count; rowCounter++)
{
AccesssRecordset.AddNew();
//Loop on column
for (Int32 colCounter = 0; colCounter < dtOutData.Columns.Count; colCounter++)
{
// for the first time... setup the field name.
if (!CheckFl)
AccesssFields[colCounter] =
AccesssRecordset.Fields[dtOutData.Columns[colCounter].ColumnName];
AccesssFields[colCounter].Value = dtOutData.Rows[rowCounter][colCounter];
}
AccesssRecordset.Update();
CheckFl = true;
}
AccesssRecordset.Close();
db.Close();
}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(dbEngine);
dbEngine = null;
}
}
Can anyone help
Thank you
Upvotes: 0
Views: 1412
Reputation: 67898
Okay, so the OpenRecordset
creates a Recordset
object. The UpdateType
it's looking for is from the UpdateTypeEnum
; you can just send a 1. And as far as the Force
goes, I think in your case you probably want to send true
. What that means is if there was somebody else that updated one of those records, their changes would not be considered and possibly lost because your updates would be forced.
Upvotes: 1