2014-03-12 97 views
-1

我的系统不会更新,和它显示这个错误,我不知道该怎么办。有什么建议么?这里是我的代码错误数据库更新查询

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','con'或'da'的 –

+2

至少一个变量为空。在方法的第一行设置一个断点并检查它们。 – Viper

回答

0

将断点上线:

com.Connection = con; 

,并通过您的代码步检查每一个变量,你去看看有什么值的时候出现。其中一个将是空的。有些东西要么没有被初始化,要么正在超出范围并被处置。