0

Can some one please help me to resolve the issue ?

I am getting the syntax error while running this code.

OleDbConnection cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=J:\CADFileLogger.accdb");
string cmdText = "INSERT INTO [tbl_Logger] (Username,FullFileName,DateOfAction,EventMode,ShortFileName) VALUES (@a,@b,@c,@d,@e)";

cn.Open();

OleDbCommand cmd = new OleDbCommand(cmdText, cn);
cmd.Parameters.Add("@a", OleDbType.WChar).Value = username;
cmd.Parameters.Add("@b", OleDbType.WChar).Value = fullfilename;
cmd.Parameters.Add("@c ", OleDbType.DBTimeStamp).Value = now;
cmd.Parameters.Add("@d ", OleDbType.WChar).Value = mode;
cmd.Parameters.Add("@e ", OleDbType.WChar).Value = filename;

cmd.ExecuteNonQuery();

cn.Close();
2
  • Could it be that Username is a reserved word or function? I'm just guessing really. Commented May 12, 2022 at 7:35
  • 1
    This is a great example of where the precise error details - and the fact that it was a compilation error rather than an exception - would have been useful to include in the question. It's entirely feasible for SQL to have a syntax error, but knowing that it was a compilation error would have ruled that out as being the immediate problem. Commented May 12, 2022 at 7:41

1 Answer 1

1

The problem is the backslash in the data source:

OleDbConnection cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=J:\CADFileLogger.accdb");

Either put an @ in front of the connection string or escape the backspace:

OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=J:\CADFileLogger.accdb");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.