Michael Mount

Michael Mount

  • NA
  • 8
  • 2.1k

Cannot insert records

Jun 9 2014 1:19 AM
I am trying to insert into an access database and cannot get it to add any records. I've been working on this problem for days and cannot get it to work. Here's my code.

Oledbconnection constring = new Oledbconnection(Connection String Here");

string strInsertEmployee = "Insert into tblEmployees(EmployeeID, EmployeeFirstName, EmployeeLastName, EmployeePhoneNumber, EmployeeVanNumber, EmployeeMeterNumber, EmployeeTabletNumber, EmployeePassword, EmployeeActive)Values(@EmployeeID, @
EmployeeFirstName, @EmployeeLastName, @EmployeePhoneNumber, @EmployeeVanNumber, @EmployeeMeterNumber, @EmployeeTabletNumber, @EmployeePassword, @EmployeeActive);

OledbCommand cmdInsertEmployee = new oledbcommand(strInsertEmployee, constring);

cmdInsertEmployee.Parameters.AddWithValue("@EmployeeID", Convert.Tostring(strEmployeeID));
cmdInsertEmployee.Parameters.AddWithValue("@EmployeeFirstName", strEmployeeFirstName);
cmdInsertEmployee.Parameters.AddWithValue("@EmployeeLastName", strEmployeeLastName);
cmdInsertEmployee.Parameters.AddWithValue("@EmployeePhoneNumber", Convert.Tostring( strEmployeePhoneNumber));
cmdInsertEmployee.Parameters.AddWithValue("@EmployeeVanNumber", strEmployeeVanNumber);
cmdInsertEmployee.Parameters.AddWithValue("@EmployeeMeterNumber", strEmployeeMeterNumber);
cmdInsertEmployee.Parameters.AddWithValue("@EmployeeTabletNumber", strEmployeeTabletNumber);
cmdInsertEmployee.Parameters.AddWithValue("@EmployeePassword", strEmployeePassword);
cmdInsertEmployee.Parameters.AddWithValue("@EmployeeActive", strEmployeeActive);

cmdInsertEmployee.Connection = constring;
constring.open();
cmdInsertEmployee.executeNonQuery();
constring.Close();

I know my connectionstring is good because I have a select statement that returns records, but I just can't get this to insert.

Thanks