11
Reply

Error - Insert data into Access database in c#

Oyetoke Toby

Oyetoke Toby

Jul 11 2016 5:25 AM
508
Pls, am having an error code when inserting data into Access database. It keeps saying there's sytank error in my INSERT INTO statement. Can any one help me to solve this.
Here is the code
 
  1. try {  
  2.                 OleDbConnection connection = new OleDbConnection(@"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\Users\DELL\Documents\EmployeesData.accdb;  
  3.                 Persist Security Info = false;");  
  4.                 connection.Open();  
  5.                 OleDbCommand cmd = new OleDbCommand("insert into EmployeeInfo (UserName, Password)values('" + UserText.Text + "', '" + PassText.Text + "')", connection);  
  6.                 cmd.ExecuteNonQuery();  
  7.                 MessageBox.Show("Inserted");  
  8.             }  
  9.             catch (Exception ex)  
  10.             {  
  11.                 MessageBox.Show("Failed" + ex.ToString());  
  12.             }  
 

Answers (11)