0

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

4

1 回答 1

1

好的,所以OpenRecordset创建了一个Recordset对象。它UpdateType正在寻找来自UpdateTypeEnum; 你可以只发送一个 1。就目前Force而言,我认为在你的情况下你可能想要发送true。这意味着如果有其他人更新了其中一个记录,他们的更改将不会被考虑并且可能会丢失,因为您的更新将被强制执行。

于 2013-02-21T12:26:05.970 回答