Updating records with a Record Set

Results 1 to 3 of 3

Thread: Updating records with a Record Set

  1. #1
    Join Date
    Dec 1969

    Default Updating records with a Record Set

    Hi I want to update fields in my database with fields that the user has filled in on a form. I want to use the Record set object to do this. I think I&#039;m missing something in my code as the database is NOT being updated but I&#039;m not getting any errors. Here is the code, can anyone see what the problem is?<BR><BR>Dim objRS<BR>Set objRS = Server.CreateObject("ADODB.Recordset")<BR>objRS.op en "Graduates", objConn, 2, 3, adCmdTable<BR><BR><BR>objRS("FirstNames") = request.form("NewName")<BR>objRS("LastName") = request.form("NewLastName")<BR>objRS("DateOfBirth" ) = request.form("NewDOB")<BR>objRS("Address1") = request.form("NewAddress")<BR>objRS("Address2") = request.form("NewAddress2")<BR>objRS("Address3") = request.form("NeweAddress3")<BR>objRS("Address4") = request.form("NewAddress4")<BR>objRS("Country") = request.form("NewCountry")<BR>objRS("Telephone") = request.form("NewTelephone")<BR>objRS("Email") = request.form("NewEmail")<BR>objRS("YearOfGraduatio n") = request.form("NewYearOfGraduation")<BR>objRS("Comp any") = request.form("NewCompanyName")<BR>objRS("Position" ) = request.form("NewPosition")<BR>objRS("CompanyAddre ss") = request.form("NewCompanyAddress")<BR><BR><BR><BR>< BR>objRS.Update <BR><BR>objRS.Close<BR>Set objRS = Nothing<BR><BR>objConn.Close<BR>Set objConn = Nothing<BR>

  2. #2
    peterjl@austec.net.au Guest

    Default RE: Updating records with a Record Set

    From your code I see that you are just openning the whole table, and then doing an update. Therefore everytime you do this you would be updating the first record. <BR><BR>I would expect to see some attempt to find a particular record based on your table&#039;s key field(s), and then update. Instead of the query being just the table name you should have a SQL select with a where clause:<BR><BR>objRS.open "select * from Graduates where ID = " & Request.Form("ID"), objConn, 2, 3<BR><BR><BR>This would bring up only the record that you want. I have used a field called [ID] because I don&#039;t know what you primary key is.<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Or else..

    or else if u r trying to add a new record then after opening the table your first statement should be <BR>"objrs.addnew" (not in quotes)

Posting Permissions

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