以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  数组输出转化  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=113483)

--  作者:扶风
--  发布时间:2018/1/16 18:42:00
--  数组输出转化
老师,现在我 s elect 数据 from {表},得到如下数据,但如下的是在同一个单元格内同一组数组
+1.02000E -9,+2.03500E -2
+1.07502E -9,+2.07700E -2
+1.07230E -9,+2.10000E -2
+1.02565E -9,+2.10200E -2
+1.04150E -9,+1.83700E -2
+1.04732E -9,+1.72900E -2
+1.06696E -9,+2.02800E -2
+1.06077E -9,+1.77500E -2
+1.05436E -9,+1.95400E -2

如何将如上数组输出 至2个单元格内?以逗号分割,且一行2个填充完另起分行,如上列就输出9行?

--  作者:有点蓝
--  发布时间:2018/1/16 21:04:00
--  
Dim  str As String = 查询的数据
Dim arr() As String = str.Replace(vbcr,"").Split(vblf)
For Each a As String In arr
    Dim r As Row = Tables("表A").AddNew
    Dim ar2() As String = a.Split(",")
    r("第一列") = ar2(0)
    r("第二列") = ar2(1)
Next

--  作者:扶风
--  发布时间:2018/1/17 18:26:00
--  
老师,提示,索引超出了数组界限。
Dim str As String ="S elect 数据 from {电容出厂} where 投产数量=\'4\' "
Dim arr() As String = str.Replace(vbcr,"").Split(vblf)
For Each a As String In arr
    Dim r As Row = Tables("CDF容量导入").AddNew
    Dim ar2() As String = a.Split(",")
    r("CAP") = ar2(0)
    r("DF") = ar2(1)
Next
DataTables("CDF容量导入").save()

且只有一个CAP的单元格有内容,为"S elect 数据 from {电容出厂} where 投产数量=\'4\' "

--  作者:有点甜
--  发布时间:2018/1/17 20:47:00
--  

请做例子具体说明你的问题

 

Dim str As String ="这里是你的数据,不是查询语句"  \'+1.02000E -9,+2.03500E -2 +1.07502E -9,+2.07700E -2
Dim arr() As String = str.Replace(vbcr,"").Split(vblf)
For Each a As String In arr
    Dim r As Row = Tables("CDF容量导入").AddNew
    Dim ar2() As String = a.Split(",")
    r("CAP") = ar2(0)
    r("DF") = ar2(1)
Next
DataTables("CDF容量导入").save()

--  作者:扶风
--  发布时间:2018/1/18 17:59:00
--  
Dim val2 As String
Dim cmd2 As New SQLCommand
cmd2.CommandText  ="(S elect 数据 from {电容出厂} where 投产数量=\'4\' )"
val2 = cmd2.ExecuteScalar()
Dim str As String = ""& val2 &""
Dim arr() As String = str.Replace(vbcr,"").Split(vblf)
For Each a As String In arr
    Dim r As Row = Tables("CDF容量导入").AddNew
    Dim ar2() As String = a.Split(",")
    r("CAP") = ar2(0)
    r("DF") = ar2(1)
Next
DataTables("CDF容量导入").save()

老师,数据是导进去了,但为什么还是报错 “索引超出了数组界限。” 导进去有80行,是因为字节长度问题吗?

--  作者:有点甜
--  发布时间:2018/1/18 18:17:00
--  

试试这样,可能命令窗口弹出什么

 

Dim val2 As String
Dim cmd2 As New SQLCommand
cmd2.CommandText  ="Select 数据 from {电容出厂} where 投产数量=\'4\' "
Dim str As String = cmd2.ExecuteScalar()
Dim arr() As String = str.Replace(vbcr,"").Split(vblf)
For Each a As String In arr
    Dim ar2() As String = a.Split(",")
    output.show(a)
    If ar2.length >= 2 Then
        Dim r As Row = Tables("CDF容量导入").AddNew
        r("CAP") = ar2(0)
        r("DF") = ar2(1)
    End If
Next
DataTables("CDF容量导入").save()