INSERT INTO/ASP/ADO- error
-
Can anybody help me? The very simple below code doesnt work. It returns a following error: "Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement. "MYDATABASE" is a access database. And "number" is a integer. THANK YOU, JARMO The code: <% dim objConn dim objTimes dim strQuery Set objConn = Server.Createobject("ADODB.Connection") Set objTimes = Server.Createobject("ADODB.Recordset") objConn.Open "MYDATABASE" strQuery="INSERT INTO Contacts (Number) VALUES (15)" set objTimes = objConn.Execute (strQuery)%>
-
Can anybody help me? The very simple below code doesnt work. It returns a following error: "Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement. "MYDATABASE" is a access database. And "number" is a integer. THANK YOU, JARMO The code: <% dim objConn dim objTimes dim strQuery Set objConn = Server.Createobject("ADODB.Connection") Set objTimes = Server.Createobject("ADODB.Recordset") objConn.Open "MYDATABASE" strQuery="INSERT INTO Contacts (Number) VALUES (15)" set objTimes = objConn.Execute (strQuery)%>
The Code, which dropped: dim objConn dim objTimes dim strQuery Set objConn = Server.Createobject("ADODB.Connection") Set objTimes = Server.Createobject("ADODB.Recordset") objConn.Open "HIERONTA" strQuery="INSERT INTO Contacts (Number) VALUES ('15')" set objTimes = objConn.Execute (strQuery)
-
The Code, which dropped: dim objConn dim objTimes dim strQuery Set objConn = Server.Createobject("ADODB.Connection") Set objTimes = Server.Createobject("ADODB.Recordset") objConn.Open "HIERONTA" strQuery="INSERT INTO Contacts (Number) VALUES ('15')" set objTimes = objConn.Execute (strQuery)
Well, first off, you don't need to create a recordset when all you are doing is INSERTing records into the database. To execute the SQL string, all you have to do is put
objConn.Execute (strQuery)
. Secondly, your SQL string should be stated like this:
strQuery = "INSERT INTO Contacts ('" & Number & "') VALUES ('15')"
I am assuming that Number is a variable you are passing into it. If it is just a number and not a variable, then the way you have it is fine. However, judging from the error message you posted, the former reason is the case (passing a variable using the wrong syntax). Lastly, you can remove the dim objTimes declaration and the Set objTimes = CreateObject("ADODB.Recordset") line. Again, all of this assuming all you are doing is INSERTing records. If you are retrieving records then you just need to change the SQL string. Try these and see what happens. If they do or if they don't, feel free to shoot me an email letting me know. Hope it helps, Tobey Unruh ================== The original message was: The Code, which dropped:
dim objConn
dim objTimes
dim strQuerySet objConn = Server.Createobject("ADODB.Connection")
Set objTimes = Server.Createobject("ADODB.Recordset")
objConn.Open "HIERONTA"
strQuery="INSERT INTO Contacts (Number) VALUES ('15')"
set objTimes = objConn.Execute (strQuery) -
The Code, which dropped: dim objConn dim objTimes dim strQuery Set objConn = Server.Createobject("ADODB.Connection") Set objTimes = Server.Createobject("ADODB.Recordset") objConn.Open "HIERONTA" strQuery="INSERT INTO Contacts (Number) VALUES ('15')" set objTimes = objConn.Execute (strQuery)
> strQuery="INSERT INTO Contacts (Number) VALUES ('15')" The error message says that you are trying to pass a string value into an integer field. Try this: strQuery="INSERT INTO Contacts (Number) VALUES (15)" Regards, Tom.
-
The Code, which dropped: dim objConn dim objTimes dim strQuery Set objConn = Server.Createobject("ADODB.Connection") Set objTimes = Server.Createobject("ADODB.Recordset") objConn.Open "HIERONTA" strQuery="INSERT INTO Contacts (Number) VALUES ('15')" set objTimes = objConn.Execute (strQuery)