![]() |
Unable to add records, syntax error in insert into statement
I'm using the below code to update values from the web page to the access database.
And I'm getting the error of "Syntax error in INSERT INTO statement". When I directly run the insert statement (which I get from this code) in the access database, the record gets added without any error. There is one more column of ID which is an autonumber field so I'm not taking it here. Code: vb
Similar code for my another program is working but I'm unable to trace where the problem is. I also tried another approach as in the below code, but this also gave the same error. Code: vb
|
Re: Unable to add records, syntax error in insert into statement
Hi,
I think you are not adding the quotes for the string that you are inserting into the database. Just try adding quotes like this for your string values: strSql = "insert into myreports(Owner, Node, IsTree, SQLCode, Param, Comment) values('" & strOwner & "', '" & strNodeText & "', 0, '" & strSQLCode & "', '" & strParam & "', '" & strComment & "')" |
Re: Unable to add records, syntax error in insert into statement
I'm doing that using chr(34)
Dim strOwner As String = Chr(34) & Session("loginname") & Chr(34) I tried both ways but it did not work. |
Re: Unable to add records, syntax error in insert into statement
The autonumber field ID was giving problem.
When I included it in the insert statement, the same code ran without any problems. so currently I'm fetching the max(ID) before the insert command to make things work. It's weird but this thing got working after 2-3 months of wait. Finally after giving up I posted my problem here. Does anyone know why this could have occurred? |
Re: Unable to add records, syntax error in insert into statement
Now I'm stuck in Update section :(
|
| All times are GMT +5.5. The time now is 16:43. |