2013-07-01 195 views
0

我试图更新我的数据库。不知何故,我的编码没有错误,但数据并未更新数据库中的值。下面是我的代码c#更新数据库但不更新数据库

SqlCeConnection conn = new SqlCeConnection("Data Source = Program Files\\PROGRAM\\DATABSE.sdf"); 
conn.Open(); 

SqlCeCommand command1 = new SqlCeCommand("Update LOT_ATT SET UPI ='" + txtUPI.Text + "' WHERE HEX_ID = (Select UPI from LOT_ATT Where ID ='" + txtUPI.Text + "'", conn); 
SqlCeCommand command2 = new SqlCeCommand("Update LOT_ATT SET NEGERI='" + txtNegeri.Text + "'WHERE HEX_ID = (Select NEGERI from LOT_ATT Where ID ='" + txtUPI.Text + "'", conn); 
SqlCeCommand command3 = new SqlCeCommand("Update LOT_ATT SET DAERAH='" + txtDaerah.Text + "'WHERE HEX_ID = (Select DAERAH from LOT_ATT Where ID ='" + txtUPI.Text + "'", conn); 
SqlCeCommand command4 = new SqlCeCommand("Update LOT_ATT SET MUKIM ='" + txtMukim.Text + "'WHERE HEX_ID = (Select MUKIM from LOT_ATT Where ID ='" + txtUPI.Text + "'", conn); 
SqlCeCommand command5 = new SqlCeCommand("Update LOT_ATT SET LOT ='" + txtLot.Text + "'WHERE HEX_ID= (Select LOT from LOT_ATT Where ID ='" + txtUPI.Text + "'", conn); 
SqlCeCommand command6 = new SqlCeCommand("Update LOT_ATT SET AREA='" + txtArea.Text + "'WHERE HEX_ID = (Select AREA from LOT_ATT Where ID ='" + txtUPI.Text + "'", conn); 

conn.Close(); 
MessageBox.Show("Updated!"); 

回答

1

您需要执行您的命令。只是定义它们不会执行它们。

command1.ExecuteNonQuery(); 
command2.ExecuteNonQuery(); 
// etc, etc. 

请确保在关闭连接之前执行此操作。

+0

仍然以某种方式,它没有更新我的数据库。 – user2539930