Vb6 Record Updation Error

爱⌒轻易说出口 提交于 2019-12-24 05:49:48

问题


In vb6, a form containing following values and here is the screenshot link for the sample values !

And I am using Ms Access 2007 and it contains a table named "studentexamdetail" contains

    heading(Admno,Semester,Subjectcode,Regular_Arrear,Fee) 

And my doubt is when i click "Save" button in above form(see screenshot), then admission number,semester,all the subjectcode, regular_arrear(we can write manually) and Fee should saved in the "studentexamdetail" table but it stores 1st value only when i use this method !

    rs2.Open "select * from studentexamdetail", con, 1, 3
    Do Until rs2.EOF
    rs2.AddNew
    rs2!AdmnNo = admno.Caption
    rs2!semester = semester.Caption
    rs2!Subjectcode = rs.Fields("Subjectcode")
    rs2!Regular_Arrear = "Regular"
    rs2!Fee = rs.Fields("Fee")
    rs2.Update
    rs2.MoveNext
    MsgBox "Record Saved!"
    Loop

What changes should i made to store all the values and not 1st value only? What i need is, I shown below :

    Admno Semester Subjectcode Regular_Arrear Fee
    1471     V       RMSC1        Regular     440
    1471     V       RMSC3        Regular     440
    1471     V       RMSC2        Regular     320

I want to save values in that table as like above only !


回答1:


The code adds a new row to the end of the rs2 recordset. Then it calls .MoveNext, which positions the recordset at .EOF. So the Loop condition is then True, which means it doesn't loop.

It seems you have another recordset, rs. Perhaps that is the one you should loop through instead of rs2.




回答2:


I have solved the problem by replacing the "rs2.movenext" to "rs.movenext" and you can see the rs recordset value in the comment above and i just placed another piece of code "rs2.close"

   Do Until rs.EOF
   rs3.Open "select * from studentexamdetail", con, 1, 3
   rs3.AddNew
   rs3!AdmnNo = admno.Caption
   rs3!semester = semester.Caption
   rs3!Subjectcode = rs.Fields("Subjectcode")
   rs3!Regular_Arrear = "Regular"
   rs3!Fee = rs.Fields("Fee")
   rs3.Update
   rs3.Close
   rs.MoveNext
   Loop
   MsgBox "Record Saved!"

Thanks God !



来源:https://stackoverflow.com/questions/14335287/vb6-record-updation-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!