Click to See Complete Forum and Search --> : Add new record to a Database


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

TecH_BoY
12-03-2004, 10:09 AM
i receive this error msg :



Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access 97 Driver] Operation must use an updateable query.

chrismartz
12-03-2004, 10:56 AM
not updatable is usually because you do not have rights to change the database that is in the folder. make sure the folder with your database is updatable through the security tab in the properties of the folder.

TecH_BoY
12-04-2004, 11:58 AM
Yup, you r right. Problem solved. Thanx alot pal......