Looping through database records

Results 1 to 2 of 2

Thread: Looping through database records

  1. #1
    Join Date
    Dec 1969

    Default Looping through database records

    Hello,<BR><BR>I am trying to read fields from a form and then insert it into the database, BUT I need to read everything in the form and put it against teh first employee name and number and then read everything again and put it against the second employee name and number. the code might make more sense so I am attaching it. Right now the way it is, it add the information of the first employee into the database but when it goes to do the next one it gives the following error<BR>Provider error &#039;80040e1b&#039; <BR><BR>Identity cannot be determined for newly inserted rows. <BR><BR>/english/karentest/testadd.asp, line 41 <BR><BR>here is the code for testadd.asp<BR>&#060;%@ Language = "VBScript"%&#062;<BR>&#060;HTML&#062;&#060;Body&#0 62;Thank you for Submitting <BR> <BR><BR><BR>&#060;%<BR>&#039;Declare all local variables<BR><BR>dim conn<BR>dim rs<BR>dim strID<BR>dim strconn<BR>dim I<BR>dim empname<BR>dim empno<BR><BR>&#039;set a local variable to my DSN-less connection String<BR>strconn = "DBQ=" & Server.MapPath("tracking.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"<BR><BR>&#039;Create the Connection object<BR>set conn = server.createobject("adodb.connection")<BR>conn.op en strconn<BR><BR>&#039;Create the recordset object<BR>set rs = server.createobject("adodb.recordset")<BR>&#039;Th is statement opens the table so we can add a record notice the addnew<BR>&#039;The 2, 2 is how the table is opened there are many ways it can be opened<BR>rs.open "Recordss", conn, 2, 2<BR><BR>&#039;Use the addnew method of the recordset object to add a record<BR>rs.addnew<BR>&#039;Set the table column = to my input text box from my form<BR><BR>For I = 0 To 2<BR> empname =""<BR> empno = ""<BR> empname = "EmployeeName" & I<BR> empno = "EmployeeNo" & I<BR><BR> while ((request.form(empname)) &#060;&#062; "")<BR>if ( ((len(request(empno))) = 9) Or ((request(empno)) = "" ) ) then <BR><BR> rs("Role")=request.form("Role")<BR><BR> rs("SDay")= request.form("SDay")<BR> rs("SMonth") = request.form("SMonth")<BR> rs("SYear") = request.form("SYear")<BR><BR> rs("EDay")= request.form("EDay")<BR> rs("EMonth") = request.form("EMonth")<BR> rs("EYear") = request.form("EYear")<BR><BR> rs("Trainer")= request.form("Trainer")<BR><BR><BR> rs("Classroom") = request.form("Classroom")<BR><BR> rs("On_the_Job") = request.form("On_the_Job")<BR><BR> rs("Trainertime") = request.form("Trainertime")<BR> rs("Experttime") = request.form("Experttime")<BR> rs("TrainingUnit") = request.form("TrainingUnit")<BR> rs("EmployeeName") = request.form(empname)<BR><BR> rs("EmployeeNo") = request.form(empno)<BR><BR><BR> rs.update<BR><BR><BR>Else %&#062;<BR> &#060;Font="5"&#062;Invalid Employee Number- Hit back to return to Original form &#060;/Font&#062;<BR>&#060;%<BR>End If<BR><BR>Wend<BR>Next<BR><BR>rs.Close<BR>Set rs = Nothing<BR>conn.Close<BR>Set conn = Nothing<BR><BR>%&#062;<BR><BR>&#060;A HREF="testform.asp"&#062; Another Entry&#060;/A&#062;<BR>&#060;/body&#062;&#060;/html&#062;<BR><BR>thank you

  2. #2
    Join Date
    Dec 1969

    Default Is the Empno column

    a IDENTITY column??<BR><BR>If so, then you shouldn&#039;t be inserting values for it from the ASP page(Unless you have SET IDENTITY OFF). It will insert a value by itself.<BR><BR>Also isn&#039;t <BR>rs("EmployeeNo") = request.form(empno)<BR>inserting the same value for every row. So if empno is the primary key column, you will get an error.<BR><BR>

Posting Permissions

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