Question : C# Database connection query

Please find below my coding
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\test1\Desktop\\Projects\\Payroll\\Index\\PayrollDB.mdb;Persist Security Info=True;Jet OLEDB:Database Password=123456");
           aConnection.Open();

            OleDbCommand  cmd = aConnection.CreateCommand();
           
               

               cmd.Parameters.Add("@EmployeeNumber", OleDbType.VarChar).Value = txtEmpNumber.Text;
              cmd.Parameters.Add("@Title", OleDbType.VarChar).Value = cmbTitle.Text;
              cmd.Parameters.Add("@FirstName", OleDbType.VarChar).Value = txtFirstName.Text;
              cmd.Parameters.Add("@MiddleName", OleDbType.VarChar).Value = txtMName.Text;
              cmd.Parameters.Add("@Surname", OleDbType.VarChar).Value = txtSurname.Text;
              cmd.Parameters.Add("@Address1", OleDbType.VarChar).Value = txtAddress1.Text;
              cmd.Parameters.Add("@Address2", OleDbType.VarChar).Value = txtAddress2.Text;
              cmd.Parameters.Add("@HomeTelephone", OleDbType.VarChar).Value = txtHomeTelephone.Text;
              cmd.Parameters.Add("@Email", OleDbType.VarChar).Value = txtEmail.Text;
              cmd.Parameters.Add("@ExtensionNumber", OleDbType.VarChar).Value = txtExNumber.Text;
              cmd.Parameters.Add("@Sex", OleDbType.VarChar).Value = txtmale.Text;
             
              cmd.Parameters.Add("@Note", OleDbType.LongVarChar).Value = txtNote.Text;
              cmd.CommandText = "insert into Employees (EmployeeID,Tittle,FirstName,MiddleName,Surname,Address1,Address2,HomeTelephone,Email,ExtensionNumber,Sex,Username,Note)"
              + "values(@EmployeeNumber,@Title,@FirstName,@MiddleName,@Surname,@Address1,@Address2,@HomeTelephone,@Email,@ExtensionNumber,@Sex,'test',@Note)";

               cmd.ExecuteNonQuery();
                   

             
               aConnection.Close();


Its showing Error called  "Syntax error in INSERT INTO statement"

But i can't find any error. all the Data type are Text and only Note field is Memo data type.

Can any one help me to solve above issue.thx

Answer : C# Database connection query

Actually, on the print on line 39, it should probably just be

print @err if @err;

since I never stripped the newlines from the output (to do that you can just add to line 37 "my @err = map { chomp; $_ } grep ...").
Random Solutions  
 
programming4us programming4us