Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xlsx|Excel文件|*.xls"
dlg.MultiSelect = True '允许选择多个文件
If dlg.ShowDialog = DialogResult.OK Then
For Each fl As String In dlg.FileNames
Dim mg As New Merger
mg.Format = "excel" '指定格式
mg.SourcePath = fl
Dim Book As New XLS.Book(fl)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
mg.SourceTableName = Sheet.name & "$" '指定要合并的表
mg.DataTableName = "汽配费用查询表" '指定接收数据的表
DataTables("汽配费用查询表").LoadFilter = "[_Identify] Is null"
DataTables("汽配费用查询表").Load()
mg.Merge()
Next
Dim stbl As String = "汽配费用查询表" '合并数据后的查询表
Dim dtbl As String = "汽配费用" '要保存的数据表
Dim cmd As New SQLCommand
cmd.C '外部数据源名称
Dim sql1, sql2 As String
For Each c As Col In Tables(stbl).Cols
sql1 + = c.Name & "," '在VB.net中, a += b 等同于 a = a + b
Next
For Each r As Row In Tables(stbl).Rows
sql2 = ""
For Each c As Col In Tables(stbl).Cols
If c.IsDate Then
sql2 + = "'" & r(c.Name) & "'" & ","
ElseIf c.IsString Then
sql2 + = "'" & r(c.Name) & "',"
ElseIf c.IsBoolean Then
If r(c.Name) = True Then
sql2 + = 1 & ","
ElseIf r(c.Name) = False Then
sql2 + = 0 & ","
End If
Else
sql2 + = r(c.Name) & ","
End If
Next
cmd.CommandText + = "InSert Into " & dtbl & " (" & sql1.Trim(",") & ") Values (" & sql2.Trim(",") & ");"
Next
cmd.CommandText = cmd.CommandText.Trim(";") 'CommandText字符型,用于设置SQL命令
MessageBox.Show(1)
cmd.ExecuteNonQuery() 'ExecuteNonQuery用于执行不返回任何值的SQL命令,例如DELETE和UPDATE命令。该方法会返回一个整数,表示受影响的行数。
MessageBox.Show(2)
DataTables(dtbl).Load '加载目的数据表
End If