在狐表导入EXCEL文件,6000条数据,处理时间10秒
如果直接保存,大概要12分钟
试着用sql语句生成,因为数据每次都要更新,所以我是清空表然后新增行,所以都是Insert命令,还是要10分钟
求老师给个方法,6000条数据保存就要十分钟,有没有好的办法
自己瞎凑的代码如下
Dim p As WinForm.ProgressBar = e.Form.Controls("ProgressBar1")
p.Visible = True
Dim file As WinForm.TextBox = e.Form.Controls("file")
Dim filename As String = file.Value
If file.Value = "" Then
MessageBox.show("文件不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else Dim test As String = filename.SubString(filename.Length - 3)
If test <> "csv" And test <> "xls" And test <> "lsx"Then
MessageBox.show("文件不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Dim Book As New XLS.Book(filename)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("储蓄台账").StopRedraw()
DataTables("储蓄台账").DeleteFor("")
Dim cmd1 As new SQLCommand
Dim cc As String
cmd1.C
cc = "truncate Table 储蓄台账"
cmd1.CommandText = cc
cmd1.ExecuteNonQuery
Dim nms() As String = {"客户号","客户姓名","上月储蓄日均","本月储蓄日均","上月储蓄余额","本月储蓄余额","活期存款余额","活期存款月日均"}
Dim cn As Integer = Sheet.Rows.Count
p.Maximum = cn - 1 '设置最大值
p.Minimum = 0 '设置最小值
p.Value = 0 '设置当前值
For n As Integer = 1 To Sheet.Rows.Count -1
Dim bh As String = sheet(n,0).Text
Dim bha As String = bh.SubString(bh.Length - 8)
Dim fdr As DataRow = DataTables("商户台账").Find("客户号 = '" & bha & "'")
If fdr IsNot Nothing Then
Dim dr As DataRow = DataTables("储蓄台账").AddNew()
dr(nms(0)) = bha
For m As Integer = 1 To nms.Length - 1
dr(nms(m)) = Sheet(n,m).Value
Next
dr("工号") = fdr("工号")
Dim cd As String = "('" & dr("客户号") & "','" & dr("客户姓名") & "'," & dr("上月储蓄日均") & "," & dr("本月储蓄日均") & "," & dr("上月储蓄余额") & "," & dr("本月储蓄余额") & "," & dr("活期存款余额") & "," & dr("活期存款月日均") & "," & dr("工号") & ")"
Dim cmd As new SQLCommand
cmd.C
Dim c As String = "INSERT INTO [sq_opldg52004].[储蓄台账] (客户号,客户姓名,上月储蓄日均,本月储蓄日均,上月储蓄余额,本月储蓄余额,活期存款余额,活期存款月日均,工号) VALUES " & cd
cmd.CommandText = c
cmd.ExecuteNonQuery
End If
If n Mod 100 = 0 Then
p.Value = n
End If
Next
Tables("储蓄台账").ResumeRedraw()
msgbox("共导入: " & cn & " 条数据!")
Forms("导入存款").Close
End If
End If