我有一个连接到访问数据库的小程序,我想做的是通过编辑表单更新(编辑)选定的记录。当我执行我的代码时,我得到这个错误:
System.Data.OleDb.OleDbException was unhandled
Message=Syntax error (missing operator) in query expression '5346 S. Eubank blvd'.
Source=Microsoft Access Database Engine
ErrorCode=-2147217900
不用说,它是为地址字段..
这是我的代码块:
private void saveChangeBtn_Click(object sender, EventArgs e)
{
Customer.SetCustID(Convert.ToInt32(editIdTB.Text));
Customer.SetFirstName(editFirstNameTB.Text);
Customer.SetLastName(editFirstNameTB.Text);
Customer.SetAddress(editAddressTB.Text);
Customer.SetPhoneNum(editPhoneTB.Text);
Customer.SetEmail(editEmailTB.Text);
using (OleDbConnection connect = new OleDbConnection(connectionString))
{
OleDbCommand cmd = new OleDbCommand();
connect.Open();
cmd.Connection = connect;
cmd.CommandText = "UPDATE Customers SET [Customer ID]=" + Customer.GetCustId() +
", [First Name]=" + Customer.GetFirstName() +
", [Last Name]=" + Customer.GetLastName() +
", [Address]=" + Customer.GetAddress() +
", [Phone Number]=" + Customer.GetPhoneNum() +
", [Email Address]=" + Customer.GetEmailAddress() +
", WHERE [Customer ID]=" + editIdTB.Text + "";
cmd.ExecuteNonQuery();
connect.Close();
MessageBox.Show("Changes made successfully!", "Success!", MessageBoxButtons.OK);
}
this.Close();
}