我試圖用OLEDB替換Excel 2007中的表。OLEDB插入到替換表中的行
首先,我正在執行命令「Drop Table」,而不是「Create Table」,它工作正常。
但是,如果我現在想要將數據("INSERT INTO")
插入到此表中,則會失敗。 OleDbCommand.ExecuteNonQuery()
沒有錯誤或異常,最後的事務提交成功,數據庫只是空的。
任何想法爲什麼?
connection.Open();
string access_com = "DROP TABLE " + globalPrefix + prefix + TableName;
OleDbCommand execute = new OleDbCommand(access_com, connection);
try
{
execute.ExecuteNonQuery();
}
catch (Exception ex)
{
ConfigDataSet.Log.AddLogRow("The program cannot drop table you want. Close the file with it and run program again!", 1);
return 1;
}
access_com = "CREATE TABLE [" + globalPrefix + prefix + TableName + "]" + fieldString + ")";// CONSTRAINT PK" + TableName + " PRIMARY KEY " + primaryKey + ")";
execute.CommandText = access_com;
execute.ExecuteNonQuery();
OleDbTransaction transaction = connection.BeginTransaction();
access_com = "INSERT INTO " + TableName + "(" + allfields + ")" + " VALUES (" + parametersString + ")";
OleDbCommand execute = new OleDbCommand(access_com, connection);
execute.Transaction = transaction;
try
{
execute.ExecuteNonQuery();
execute.Parameters.Clear();
}
catch (OleDbException ex)
{
ConfigDataSet.Log.AddLogRow("Inserting row failed: ", 2);
failedInsertions++;
}
可以發佈一個更多的代碼..看看它.. – SenthilPrabhu
什麼樣的表(表或範圍?),你可以驗證DROp的作品? –
一張紙。我很確定,因爲我想要替換的表充滿了記錄,並且在執行代碼之後它是空的 – Jan