TecH_BoY
12-03-2004, 03:42 AM
Hi all,
I have tried adding a new record to a database using ASP. As i know the code worked. But, however i did some modification to the code and now it is not working at all. Pls help me. What i wanna do is to add the data's i entered in a form into the database.
I have attached the form, the database asp page and the access database file.
However, this is how the code looks like,
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "small_Demo"
sql="INSERT INTO customers (customerID,companyname,"
sql=sql & "contactname,address,city,postalcode,country)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("custid") & "',"
sql=sql & "'" & Request.Form("compname") & "',"
sql=sql & "'" & Request.Form("contname") & "',"
sql=sql & "'" & Request.Form("address") & "',"
sql=sql & "'" & Request.Form("city") & "',"
sql=sql & "'" & Request.Form("postcode") & "',"
sql=sql & "'" & Request.Form("country") & "')"
Response.Write(sql)
on error resume next
conn.Execute sql
if err<>0 then
Response.Write("<br> Data Not Added </br>")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
I keep on receiving the "Data Not Added" error msg. Is it my sql statement? Pls help me....
Note: i added my database file "small_Demo.mdb" to system DSN and named it as "small_Demo"
Thanx in advance
I have tried adding a new record to a database using ASP. As i know the code worked. But, however i did some modification to the code and now it is not working at all. Pls help me. What i wanna do is to add the data's i entered in a form into the database.
I have attached the form, the database asp page and the access database file.
However, this is how the code looks like,
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "small_Demo"
sql="INSERT INTO customers (customerID,companyname,"
sql=sql & "contactname,address,city,postalcode,country)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("custid") & "',"
sql=sql & "'" & Request.Form("compname") & "',"
sql=sql & "'" & Request.Form("contname") & "',"
sql=sql & "'" & Request.Form("address") & "',"
sql=sql & "'" & Request.Form("city") & "',"
sql=sql & "'" & Request.Form("postcode") & "',"
sql=sql & "'" & Request.Form("country") & "')"
Response.Write(sql)
on error resume next
conn.Execute sql
if err<>0 then
Response.Write("<br> Data Not Added </br>")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
I keep on receiving the "Data Not Added" error msg. Is it my sql statement? Pls help me....
Note: i added my database file "small_Demo.mdb" to system DSN and named it as "small_Demo"
Thanx in advance