...

View Full Version : Updating Access Database via asp form



Ted Varnson
08-09-2004, 09:42 PM
I am trying to create a processing script to update information froma form into a certain row via id number. I have the form set up to send the title, description, and id (as a private field) I just cant get it to process. I think my problem is my sql statement. Can you all have a look?


<%
Dim newid, newtitle, newdescription, data_source, con, StrSql

' A Function to check if some field entered by user is empty
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function

' Receiving values from Form
newid = ChkString(Request.Form("id"))
newtitle = ChkString(Request.Form("title"))
newdescription = ChkString(Request.Form("description"))
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("---")
StrSql = "UPDATE calendar SET title = '" & newtitle & "', description = '" & newdescription & "' WHERE id = #" & newid & "#"

' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute StrSql

' Done. Close the connection
con.Close
Set con = Nothing

Response.Redirect "confirmation.htm"
%>

My rows are named id, title, and description, same with my form fields

needhelp26
08-10-2004, 12:35 AM
If newid is a autonumber or number datatype, sql statement should be:

WHERE [id] = & newid

Try and see because numbers datatype should not be in quotes.

glenngv
08-10-2004, 03:05 AM
If newid is a autonumber or number datatype, sql statement should be:

WHERE [id] = & newid

Try and see because numbers datatype should not be in quotes.
If it's indeed a number, then it should be:

StrSql = "UPDATE ... WHERE id=" & newid

needhelp26
08-11-2004, 03:20 AM
Thankyou again. I always find my ways thru trial and error.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum