我有来自数组的数据如下:
(AuthName1,AuthAddr1,AuthEmail1〜AuthName2,AuthAddr2,AuthEmail2〜)
所以我使用以下代码将其拆分:
<%
dim authinfo
dim arr1
arr1 = Split(authinfo,"~")
for each item in arr1
response.write item
response.write ("<br>")
next
%>
它给出了以下结果:
AuthName1,AuthAddr1,AuthEmail1 AuthName2,AuthAddr2,AuthEmail2
然后我更新上面的代码,如下所示分割每个部分:
<%
dim authinfo
dim arr1
arr1 = Split(authinfo,"~")
for each item in arr1
arr2 = split(item,",")
for each item2 in arr2
response.Write item2
response.Write ("<br>")
response.write ("<br>")
next
%>
我想要的是使用sql将(arr2)中的每个项目插入到数据库表中 是(ID,AuthorName,AuthorAddress,AuthorEmail)
答案 0 :(得分:0)
INSERT INTO
[dbo].[TestTable1]
([F1], [F2], [F3])
VALUES
(arr2 (0), arr2 (1), arr2 (2))
因为“arr2”是数组,你可以使用arr2(0),arr2(1),arr2(2),其中 arr2(0)= AuthName1 arr2(1)= AuthAddr1 arr2(2)= AuthEmail1
另外,请从
更改 for each item2 in arr2
response.Write item2
到
for each item2 in arr2
response.Write item2
next
最后:
dim authinfo
dim arr1
authinfo = "AuthName1,AuthAddr1,AuthEmail1~AuthName2,AuthAddr2,AuthEmail2"
arr1 = Split(authinfo,"~")
for each item in arr1
arr2 = split(item,",")
Response.Write arr2 (0) & ";" & arr2 (1) & ";" & arr2 (2)
'### Your SQL statement should be there !
next
请注意! 不要忘记验证数组大小!