0

我正在尝试制作一个使用帐号更新帐户昵称的按钮,但出现错误。

在此处输入图像描述

  private void change_nickname_Click(object sender, EventArgs e)
    {
        try
        {
            connection.Open();
            OleDbCommand command = new OleDbCommand();
            command.Connection = connection;
            string query = "update customers set [CustomerCode]='" + customercode.Text + "',[CustomerName]='" + customername.Text + "',[Address]='" + customeraddress.Text + "',[PhoneNumber]='" + customerphone.Text + "',[Account]='" + Account + "',[AccountNickname]='" + accountnickname.Text + "',[Overdraft]='" + overdraft.Text + "' where AccountNumber=" + accountnumber.Text + "";
            MessageBox.Show(query);
            command.CommandText = query;

            command.ExecuteNonQuery();
            MessageBox.Show("Data updated successfuly!");
            connection.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error: " + ex);
        }
        connection.Close();
    }
4

1 回答 1

0

是的,问题已经解决了,谢谢大家的帮助。问题就在这里。

where AccountNumber=" + accountnumber.Text + "";
        MessageBox.Show(query);

我把它改成了

where AccountNumber='" + accountnumber.Text + "'";
        MessageBox.Show(query);

它以某种方式起作用。

于 2015-12-05T20:31:29.060 回答