0
我與存儲客戶數據 程序工作,後來它需要改變麻煩在用C#
此訪問更新數據庫記錄是我的代碼:
private void button2_Click(object sender, EventArgs e)
{
conn.Open();
string oc = ("Update Custs Set Cname [email protected], [email protected], [email protected], [email protected], [email protected], Where NatCode Like'%" + textBox2.Text + "%'");
OleDbCommand myCommand = new OleDbCommand();
myCommand.CommandText = oc;
myCommand.Connection = conn;
myCommand.Parameters.AddWithValue("@Cname",textBox1.Text);
myCommand.Parameters.AddWithValue("@NatCode", textBox3.Text);
myCommand.Parameters.AddWithValue("@Bdate", textBox2.Text);
myCommand.Parameters.AddWithValue("@CellPhone", textBox4.Text);
myCommand.Parameters.AddWithValue("@Addr", textBox8.Text);
myCommand.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Data Changed successfully!");
}
但它不」做T改變任何東西
任何幫助,將不勝感激
我想知道爲什麼你在這裏有這麼多大括號 - 這是複製和粘貼錯誤? –
你以前昏迷哪裏還有Like之後沒有空間。也把參數放在參數中。 – mybirthname
可能只是我的意見,但對我來說,通過'textBox8'命名文本框'textBox1'是一個糟糕的選擇......爲什麼不根據它們應該包含的內容來命名這些文本? (也注意到方法名稱中的'button2') – Rafalon