我的系统无法更新,并且显示此错误,我不知道该怎么做。有什么建议?这是我的代码
private void btnupdate_Click(object sender, EventArgs e)
{
com.Connection = con;
con.Open();
string query = "UPDATE [Promissory] SET [pdate] = ?,[Edpno] = ?, [gradingperiod] = ?, [pamount] = ?, [reasons] = ?, [syid] = ? WHERE Promissoryno = ?";
var accessUpdateCommand = new OleDbCommand(query, con);
accessUpdateCommand.Parameters.AddWithValue("pdate", txtdate.Text);
accessUpdateCommand.Parameters.AddWithValue("Edpno", txtedpno.Text);
accessUpdateCommand.Parameters.AddWithValue("gradingperiod", txtgradeperiod.Text);
accessUpdateCommand.Parameters.AddWithValue("pamount", txtamount.Text);
accessUpdateCommand.Parameters.AddWithValue("reasons", txtreasons.Text);
accessUpdateCommand.Parameters.AddWithValue("syid", txtsyid.Text);
accessUpdateCommand.Parameters.AddWithValue("Promissoryno", txtpromiseno.Text); // Replace "123" with the variable where your ID is stored. Maybe row[0] ?
da.UpdateCommand = accessUpdateCommand; //This line here is the error
da.UpdateCommand.ExecuteNonQuery();
con.Close();
}
答案 0 :(得分:0)
在线上设置一个断点:
com.Connection = con;
并逐步检查每个变量,以查看它们具有的值。其中一个将为null。有些东西要么没有被初始化,要么超出范围并被处置。