2014-03-12 99 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; 

,並通過您的代碼步檢查每一個變量,你去看看有什麼值的時候出現。其中一個將是空的。有些東西要麼沒有被初始化,要麼正在超出範圍並被處置。