how to combine Two recordset data to one recordset in classic asp

旧时模样 提交于 2020-01-07 08:54:09

问题


I am calling two “stored procedures” using different database connection. I used two separate record sets in page but I required combining both in one record set along with sorting also required.

Ex: two records set Rs1, Rs2

Rs1 data

Emp_code Name Grade

001 Bcd A

004 Abc C

Rs2 data

Emp_code Name Grade

002 Xyz A

005 Zxy B

But I required to displaying following table with sorting (emp_code asc, name asc, grade asc)

Emp_code Name Grade

001 Bcd A

002 Xyz A

004 Abc C

005 Zxy B

click this link it display properly

http://i.stack.imgur.com/aNLOn.jpg


回答1:


Create a third recordset and paste the rows from RS1 and Rs2 into that new one:

set newRs = server.createobject("adodb.recordset")

for each fld in Rs1.fields
    newRs.fields.append fld
next

newRs.open

' fill data from Rs1
do while not rs1.eof
    for each fld in Rs1.Fields
        newRs(fld.name).value = fld.value
    next
    newRs.update

    rs1.movenext
loop

' fill data from Rs2
do while not rs2.eof
    for each fld in Rs2.Fields
        newRs(fld.name).value = fld.value
    next
    newRs.update

    rs2.movenext
loop

newRs.Sort = "emp_code asc, name asc, grade asc"


来源:https://stackoverflow.com/questions/21752205/how-to-combine-two-recordset-data-to-one-recordset-in-classic-asp

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