0

データベースを更新しようとしています。どういうわけか、コーディングにエラーはありませんが、データはデータベースの値を更新しません。以下は私のコードでした

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!");
4

1 に答える 1

1

コマンドを実行する必要があります。それらを定義するだけでは実行されません。

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

接続を閉じる前に、必ずこれを行ってください。

于 2013-07-01T17:41:56.683 に答える