I have a small program that connects to an access database, and what I am trying to do is update(edit) a selected record via an edit form. When I execute my code, I get this error:
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
Needless to say, it is for the Address field..
Here is my code block:
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();
}