Syntax error (Missing Operator) in Query expression ':0:1
-
Hallo Forum, I am new to this forum and I would like to get your help. I am having issues with this code. HERE is the error I am getting: Syntax error (Missing Operator) in Query expression ':0:1 Dim CustomerTrans As OleDb.OleDbTransaction = Nothing Dim MyConnection As OleDb.OleDbConnection = Nothing 'Creat connection and the transactions Object Try MyConnection = New OleDb.OleDbConnection(My.Settings.dbConnectionString) MyConnection.Open() 'Begin Transaction CustomerTrans = Myconnection.BeginTransaction 'Insert the New receipt Dim SQL As String = "Insert into Receipts (ReceiptDate,ReceiptTotal) values (:0:1)" Dim CMD1 As New OleDb.OleDbCommand CMD1.Connection = Myconnection CMD1.Transaction = CustomerTrans CMD1.CommandText = SQL CMD1.Parameters.AddWithValue(":0", Now.Date) CMD1.Parameters.AddWithValue(":1", TotalPriceTxt) CMD1.ExecuteNonQuery() CMD1.Dispose() i AM Using Access 2007 and I set t ANY HELP GIVEN IS HIGHLY APPRECIATED. i TRIED ALMOST ALL I CAN THINK OF. Thank you in advance.
What database system? Oracle? MySQL? SQL Server?
-
What database system? Oracle? MySQL? SQL Server?
-
-
-
But I am not using Named Parameters. I am really confused. I guess I have been reading way too long about this.
It looks like you think you are.
-
Hallo Forum, I am new to this forum and I would like to get your help. I am having issues with this code. HERE is the error I am getting: Syntax error (Missing Operator) in Query expression ':0:1 Dim CustomerTrans As OleDb.OleDbTransaction = Nothing Dim MyConnection As OleDb.OleDbConnection = Nothing 'Creat connection and the transactions Object Try MyConnection = New OleDb.OleDbConnection(My.Settings.dbConnectionString) MyConnection.Open() 'Begin Transaction CustomerTrans = Myconnection.BeginTransaction 'Insert the New receipt Dim SQL As String = "Insert into Receipts (ReceiptDate,ReceiptTotal) values (:0:1)" Dim CMD1 As New OleDb.OleDbCommand CMD1.Connection = Myconnection CMD1.Transaction = CustomerTrans CMD1.CommandText = SQL CMD1.Parameters.AddWithValue(":0", Now.Date) CMD1.Parameters.AddWithValue(":1", TotalPriceTxt) CMD1.ExecuteNonQuery() CMD1.Dispose() i AM Using Access 2007 and I set t ANY HELP GIVEN IS HIGHLY APPRECIATED. i TRIED ALMOST ALL I CAN THINK OF. Thank you in advance.
-
Should there not be a comma between the two parameter identifiers like:
Dim SQL As String = "Insert into Receipts (ReceiptDate,ReceiptTotal) values (:0, :1)"
I think those just aren't valid names/markers.
-
Should there not be a comma between the two parameter identifiers like:
Dim SQL As String = "Insert into Receipts (ReceiptDate,ReceiptTotal) values (:0, :1)"
Rick Thanks for your input. I have tried that already and it didn't work for me. it gives me another error: "Data type mismatch in criteria expression" Is the anyone out the who can suggest what I should do with this error? I will really appreciate in advance. Thank you
-
I think those just aren't valid names/markers.
-
PieBALDconsult, What do you mean by not valid names? I have have them on my database exactly as you can see it. I have checked everything on the naming....is there anything you think I am missing? Please help! Thanks.
You're more familiar with what exactly you are doing. Typically, names aren't allowed to start with a digit. My experience with Access (via OleDb) is that question marks (
?
) are preferred, but that names can be used if they're kept in order (as yours are). I have also only see a colon (:
) used for parameter names in Oracle. -
You're more familiar with what exactly you are doing. Typically, names aren't allowed to start with a digit. My experience with Access (via OleDb) is that question marks (
?
) are preferred, but that names can be used if they're kept in order (as yours are). I have also only see a colon (:
) used for parameter names in Oracle. -
PIEBALD Consult, Thanks for your feedback. It really got me thinking. and I got it to work. All I had to do is take the (:) out. Man, I spent so much to do that. I really appreciate how you help me focus on where I wanted. Thank you again.
I'd be interested to see what you have now.
-
I think those just aren't valid names/markers.