I am working with a program which stores customers data and later it needs to be changed
this is my code :
private void button2_Click(object sender, EventArgs e)
{
conn.Open();
string oc = ("Update Custs Set Cname =@Cname, NatCode=@NatCode, Bdate=@Bdate, CellPhone=@CellPhone, Addr=@Addr, 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!");
}
But it doesn't do change anything
any help would be appreciated
Are you sure Where NatCode Like'%" + textBox2.Text + "%'"
contains any row?
in myCommand.Parameters.AddWithValue("@Bdate", textBox2.Text);
you are using textBox2
for Birthday
and in Query you use it for NationalCode
.
I guess the problem is it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.