Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    Location
    SW England
    Posts
    102

    Unanswered: .Update creates new record but all fields null

    Hi guys, I have made several Access-based CMSs but now I am using SQL Server. I can read the records but my first attempts at writing are resulting in new records (with new ID) but all the fields are null.
    I am posting the data from a form to the same page and an if /then statement catches the flag in the URL and runs the update script below. All the field names are correct.
    if request.QueryString("add")<> "" then
    Dim rsUpdateEntry
    Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
    rsUpdateEntry.Open "SELECT * from generic_country_info" , oConn, 2, 3

    rsUpdateEntry.AddNew

    rsUpdateEntry.Fields("title1") = Request.Form("title1")
    rsUpdateEntry.Fields("body1") = Request.Form("body1")
    rsUpdateEntry.Fields("title2") = Request.Form("title2")
    rsUpdateEntry.Fields("body2") = Request.Form("body2")
    rsUpdateEntry.Fields("title3") = Request.Form("title3")
    rsUpdateEntry.Fields("body3") = Request.Form("body3")
    rsUpdateEntry.Fields("title4") = Request.Form("title4")
    rsUpdateEntry.Fields("body4") = Request.Form("body4")
    rsUpdateEntry.Fields("title5") = Request.Form("title5")
    rsUpdateEntry.Fields("body5") = Request.Form("body5")
    rsUpdateEntry.Fields("image1") = Request.Form("attach1")
    rsUpdateEntry.Fields("image2") = Request.Form("attach2")
    rsUpdateEntry.Fields("image3") = Request.Form("attach3")
    rsUpdateEntry.Fields("image4") = Request.Form("attach4")
    rsUpdateEntry.Fields("image5") = Request.Form("attach5")
    rsUpdateEntry.Fields("country") = Request.Form("country")
    rsUpdateEntry.Fields("dest_url") = Request.Form("dest_url")


    rsUpdateEntry.Update

    rsUpdateEntry.Close
    Set rsUpdateEntry = Nothing
    end if
    Thanks
    Mark

  2. #2
    Join Date
    Dec 2002
    Posts
    1,245
    At the risk of offending you, may I suggest that you instead consider a stored procedure? At first it require a bit more effort and thought, but in the long run, stored procedures are a sensible way to handle database activity (including updates, inserts, selects and deletes).

    As for the code you've written, are you sure that the .Add is in the right place? It looks to me (though I don't write my code this way) like it should come after you have assigned all of the values.

    Regards,

    hmscott
    Have you hugged your backup today?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •