-- 作者:东坡一剑
-- 发布时间:2013/9/8 0:22:00
-- 从Excel导入不重复的数据
想从一个Excel表中提取不重复的数据添加到foxtable的外部表中,代码如下:
Dim dlg As new OpenFileDialog dlg.Filter = "Excel文件|*.xls" Dim fl As String
If dlg.ShowDialog = DialogResult.OK Then fl = dlg.FileName End If MessageBox.Show(1) Dim dic As Dictionary(Of String ,String) Dim cmd As new SQLCommand cmd.C cmd.CommandText = "select * From {颜色编码}" Dim dt As DataTable = cmd.ExecuteReader() MessageBox.Show(2) Dim book As new XLS.Book(fl) Dim sheet As XLS.Sheet = book.Sheets("sheet1") MessageBox.Show(2.1) For i As Integer = 1 To sheet.Rows.Count - 1 Dim dr As DataRow = dt.Find("色码 =\'" & sheet(i,1).Value & "\' And 品牌 =\'" & sheet(i,0).Value & "\'") MessageBox.Show(2.2) If dr Is Nothing AndAlso dic.ContainsKey( sheet(i,1).Value) = False Then MessageBox.Show(2.3) dic.Add(sheet(i,1).Value,sheet(i,0).Value & "," & sheet(i,2).Value) End If Next MessageBox.Show(3) For Each key As String In dic.keys Dim dr As DataRow = DataTables("颜色编码").AddNew() dr("色码") = key dr("品牌") = dic(key).Substring(0, dic(key).Indexof(",")) dr("颜色") = dic(key).Substring(dic(key).Indexof(",") + 1) Next
测试时,MessageBox.Show(2.2)可以正常运行,错误提示为:
Next
此主题相关图片如下:2013-09-08 00 19 08.png

找不到问题所在,请教大家支支招!
[此贴子已经被作者于2013-9-8 0:27:05编辑过]
|