关于asp里数据拆分问题

来源:百度知道 编辑:UC知道 时间:2024/05/31 14:53:06
我的数据库表里有个字段和N条记录,其中一条记录的内容形式如下
|1244&张三&1&13&|1241&李四&1&13&|891&赵武&2&9&|892&麻子&1&9&|443&二蛋&1&4.5&
我想把其中一条记录输出到一个表格,把上述内容分成4列和若干行,如下
1244 张三 1 13
1241 李四 1 13
891 赵武 2 9
....
请教如何写asp代码?
<%
set rs=server.createobject("adodb.recordset")
sql="select * from orders where orderid=65"
rs.open sql,conn,1,1
orderxq=rs("orderxq")

orderxq=split(orderxq,"|")
for n=1 to ubound(orderxq)
d=orderxq(n)
j=mm(d,0)
set rs2=server.createobject("adodb.recordset")
sql2="select * from caipin where caiid='"&j&"'"
rs2.open sql2,conn,1,1
response.Write rs2("cainame")
next

function mm(b,k)
c=split(b,"&")
response.Write c(k)
end function
%>
这样输出后说是BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
不知道为什么,数据库里明明有这条记录,查不到。。。

用split函数拆分

设你的这个记录读入到TXT变量中

s=split(TXT,"|") '按|符号拆开后读入到S数组中
其中
S(1)=1244&张三&1&13&
S(2)=1241&李四&1&13&
S(3)=891&赵武&2&9&
*****************************************用循环做
s=split(TXT,"|") '按|符号拆开后读入到S数组中

for i=1 to ubound(S) 'ubound获取最大下标值

k=split(S(i),"&") '按&符号拆开后读入到另一个数组中再分别调用即可
response.write k(0) '1244 '注意这是从0开始的,因为字符串首没有分隔符,与上面有所不同
response.write k(1) '张三
next
********************************

直接用rs.field(1),s.field(2)...不成吗?

Option Explicit

Private Sub Command1_Click()
Dim mystr As String
Dim i As Integer, j As Integer
Dim myarr1, myarr2
Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Set xlBook = xlApp.Workbooks.Open("d:\12.xls")
Set xlSheet = xlApp.Worksheets("Sheet1")
xlApp