|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I want to submit the user_id, user_name, subject, current date and a message to be inserted into a table named Messages using the following script:
sub db_insert_send_message sql = "INSERT INTO Messages" & _ "(" & _ "user_id," & _ "user_name," & _ "subject," & _ "message," & _ "dt_created," & _ ") VALUES (" & _ "" & to_sql(user_id,"number") & "," & _ "" & to_sql(user_name,"text") & "," & _ "" & to_sql(subject,"text") & "," & _ "" & to_sql(message,"text") & "," & _ "" & to_sql(dt_created,"text") & "," & _ "" 'response.write sql on error resume next cn.Execute(sql) if err.Number <> 0 then b_error = true error_list.add "db_insert_send_message" & err.Number ,"The database insert failed. " & err.Description else set rs = cn.Execute("SELECT @@IDENTITY") message_id = rs(0) rs.Close msg_list.add "db_insert_send_message","The database insert was successful." end if on error goto 0 end sub but i get: The database insert failed. Syntax error in INSERT INTO statement. what could be the problem? please help. |
|
#2
|
||||
|
||||
|
When inserting strings into a database, you need to place single quotes around them (That may be handled by your to_sql function?). Also, your last fieldname has a comma after, which has to be removed. Looks like your missing the closing bracket around the values too (and get rid of the last comma in the value list).
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > insert failed error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|