Hello everybody,
I am using following codes to insert the data to the database.but I am getting error please help me with this.

codes:
<%
Dt= Date()
Set T=Request.Form("trainer")
Set Co=Request.Form("course")
Set Ss=Request.Form("sessionstructure")
Set Sp=Request.Form("sessionpace")
Set Sc=Request.Form("sessioncontent")
Set Po=Request.Form("personalobj")
Set Pr=Request.Form("presentation")
Set I=Request.Form("Interaction")
Set Mn=Request.Form("manage")
Set Con=Request.Form("confedence")
Set Sr=Request.Form("sessionrate")
Set Sg=Request.Form("sessiongoal")
Set Cm=Request.Form("comment")
Set Nm=Request.Form("name")

Set Conn = Server.CreateObject("ADODB.Connection")

Set Rs = Server.CreateObject("ADODB.Recordset")

Conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("Mypgdb.mdb")

sql= "Insert into StudentFB( Trainer, Course, Sessionstructure, Sessionpace, Sessioncontent, Personalobj, Presentation, Interaction, Manage, Confidence, Sessionrate, Sessiongoal, Comment, Name, Date) VALUES ('" & T & "',' " & Co & "','"& Ss & "','" & Sp & "','" & Sc & "','" & Po & "','" & Pr & "','" & I & "','" & Mn & "','" & Con & "','" & Sr & "','" & Sg & "','" & Cm & "','" & Nm & "', '" & Dt & "')"

Rs.Open sql, Conn
//Conn.Execute(sql)

Rs.AddNew

Rs.Update
Rs.Close
Set Rs = Nothing
conn.Close

Set Conn = Nothing
%>


I am getting the error:

Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in INSERT INTO statement.
/mpg/02.asp, line 50

Thanks

There's actually many things that will give you errors here.
1. First of all, you don't "set" those variables, you have to declare them by using "DIM". So you can either Dim them first then set values to them, or just insert them directly into the SQL query.
2. No need for a recordset unless you are retrieving or updating existing data.
3. rs.AddNew is only used if you wish to have a recordset while inserting information, this way you need it like this:

rs.Open
  rs.AddNew
  rs("columnname") = Trim(Request.Form("fieldname"))
  rs("columnname") = Trim(Request.Form("fieldname"))
  rs.Update
  'do a requery to make sure no data was skipped.
  rs.Requery
  rs.Close

  rs = ""
  set rs = nothing

4. For queries, keep in mind that all text columns need to be inserted with the following quotes: ("INSERT ... ('" & .. & "', .... ) )", and for all integer columns no quotes are needed: ("INSERT ... (" & .. & ", .... ) )"

Now this is the code you should use:

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("Mypgdb.mdb")
Conn.Open

sql= "Insert into StudentFB( Trainer, Course, Sessionstructure, Sessionpace, Sessioncontent, Personalobj, Presentation, Interaction, Manage, Confidence, Sessionrate, Sessiongoal, Comment, Name, Date) VALUES ('" & Trim(Request.Form("trainer")) & "',' " & Trim(Request.Form("course")) & "','"& Trim(Request.Form("sessionstructure")) & "','" & Trim(Request.Form("sessionpace")) & "','" & Trim(Request.Form("sessioncontent")) & "','" & Trim(Request.Form("personalobj")) & "','" & Trim(Request.Form("presentation")) & "','" & Trim(Request.Form("Interaction")) & "','" & Trim(Request.Form("manage")) & "','" & Trim(Request.Form("confedence")) & "','" & Trim(Request.Form("sessionrate")) & "','" & Trim(Request.Form("sessiongoal")) & "','" & Trim(Request.Form("comment")) & "','" & Trim(Request.Form("name")) & "', '" & Now() & "')"

Conn.Execute(sql)

Conn.Close

Conn = ""
Set Conn = Nothing
%>
This article has been dead for over six months. Start a new discussion instead.