我正在处理Access数据库上一篇文章的更新/插入。这是代码:
string sql = string.Format("SELECT [ID], [Nome], [Data], [Completo], [Notes] FROM [Articles] WHERE [Nome]='{0}'", art.Name);
OleDbDataAdapter da = dbo.GetAdapter(sql);
DataTable dtArticolo = new DataTable("Articles");
da.Fill(dtArticolo);
DataRow drArticolo;
if (dtArticolo.Rows.Count > 0)
{
drArticolo = dtArticolo.Rows[0];
}
else
{
drArticolo = dtArticolo.NewRow();
dtArticolo.Rows.Add(drArticolo);
}
// Data
//drArticolo["ID"] = ; //? ID is PK!
drArticolo["Nome"] = art.Name;
drArticolo["Data"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
drArticolo["Completo"] = (byte)0;
drArticolo["Notes"] = !String.IsNullOrEmpty(art.Note) ? art.Note : string.Empty;
// Save
da.Update(dtArticolo);
dtArticolo.AcceptChanges();
dtArticolo.Dispose();
da.Dispose();
在“更新”上,我收到一个错误“在传递带有新行的DataRow集合时,更新需要有效的InsertCommand”。怎么了?