Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help trying to insert to database, getting error 80040e14

Status
Not open for further replies.

hutch80

Technical User
Feb 4, 2005
6
CA
Hi, I'm trying to insert a record (news item) to the database from a form. I am getting a 80040e14 error, as follows:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

/french/admin_add_science2.asp, line 135

Not quite sure where to go from here, seems like a pretty simple command. Here is the asp:

' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "frm_update_comm") Then

MM_editConnection = MM_conn_watershed_STRING
MM_editTable = "tbl_sci"
MM_editRedirectUrl = "admin_add_science2.asp"
MM_fieldsStr = "date|value|headline|value|news_item|value"
MM_columnsStr = "date|',none,NULL|headline|',none,''|news_fr|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim rs_news
Dim rs_news_numRows

Set rs_news = Server.CreateObject("ADODB.Recordset")
rs_news.ActiveConnection = MM_conn_watershed_STRING
rs_news.Source = "SELECT * FROM tbl_sci ORDER BY date DESC"
rs_news.CursorType = 0
rs_news.CursorLocation = 2
rs_news.LockType = 1
rs_news.Open()

rs_news_numRows = 0
%>


Any help is greatly appreciated!

 
hutch,


W/O seeing sql query result it's hard to determine where the syntax error is but I created a couple bogus arrays and used this: MM_tableValues = MM_tableValues & MM_columns(MM_i)

and got a leading comma. To get rid of it I did this after the for next loop:

MM_tableValuesLength = LEN(MM_tableValues) - 1
MM_tableValues = Right(MM_tableValues,MM_tableValuesLength)

...and my sql statement was corrected

I diddn't quite follow the logic with the delimiters for setting up your ...values (" & MM_dbValues & ")" (Tired ;-))...it looked like to me that you can never get it to look like this: values ('" & MM_dbValues & "')" unless hardcoded...but this is for string vars....what if a num...any checking for that so you drop the '? Hopefully this makes sense but hell I'm tired and probably should have waited for the sql result...anyways...good luck

BSL







 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top