我正在使用 Microsoft Access 2010 作为数据源创建小型库存应用程序。我的连接字符串如下所示:
<add name="ApplicationServices"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\nityaprakash\Documents\NPSInventory.accdb"
providerName="System.Data.OleDb" />
但是当更新任何记录时出现错误Object Invalid 或不再设置。我正在使用 OleDbCommand 更新记录,其中将简单更新查询作为 CommandType.Text 传递。
try
{
_dataAccess = DataAccess.GetInstance())
_dataAccess.OpenConnection();
string command_ = "UPDATE Inventory SET Item = 'MyItem', Description = 'Desc', Category = '', Location = '', Manufacturer = 'CELLo', Model = 'cell101', ReorderLevel = 10, TargetStockLevel = 200, BalanceQuantity =150, Discontinued = 0, Comments = 'Comment' Where ID = 9;";
IDbCommand cmd_ = _dataAccess.GetCommandFor(command_, CommandType.Text);
cmd_.ExecuteNonQuery();
}
finally
{
if (_dataAccess != null)
_dataAccess.CloseConnection();
}