I am trying to write some information to an access database using OleDB but I get an error. I dont know what is wrong with it. I it something to do with my SQL code?
// The program will make use of a text file for now but must use ms access database in the future.
string name = textBoxFirstName.Text;
string lname = textBoxLastName.Text;
string gender = comboBoxGender.Text;
string id = textBoxID.Text;
string province = comboBoxProvince.Text;
string city = textBoxCity.Text;
string addr = textBoxAddress.Text;
string field = textBoxField.Text;
string degree = textBoxDegree.Text;
if ((name == "") || (lname == "") || (gender == "") || (id == "") || (province == "") || (city == "")
|| (addr == "") || (field == "") || (degree == ""))
{
MessageBox.Show("Please make sure all the fields are filled in!");
return;
}
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\User\Documents\Databases\employeedb.accdb");
conn.Open();
using(OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = "Insert Into Employee (fname, lname, gender, iden, province, city, addr, field, degree)"
+ " values (" + name + ", " + lname + ", " + gender + ", " + id + ", " + province + ", "
+ city + ", " + addr + ", " + field + ", " + degree + ")";
cmd.ExecuteNonQuery();
}
conn.Close();
The runtime error happens at cmd.ExecuteNonQuery();
how do I fix this problem?