狐表在数据保存时效率不是很高用了第四种的代码:
四、多行一次插入,用 Un ion All 分隔语句 8秒
Dim dt As Date = Date.Now
Dim cmd As New SQ Command
cmd.C
Dim sql1,sql2 As String
For Each c As Col In Tables("导入订单").Cols
sql1 + = c.Name & ","
Next
For Each r As Row In Tables("导入订单").Rows
sql2 = ""
For Each c As Col In Tables("导入订单").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 + = "Select " & sql2.Trim(",") & vbcrlf & "Union All" & vbcrlf
Next
cmd.CommandText = "InS ert Into 订单 (" & sql1.Trim(",") & ")" & vbcrlf & cmd.CommandText.SubString(0,cmd.CommandText.Length - 11)
cmd.ExecuteNonQuery
DataTables("订单").Load
Dim tp As TimeSpan
tp = Date.Now - dt
MessageBox.Show(tp.TotalSeconds)
数据量不大时,效果挺好的
今天用这种方法,往云服务器的sql数据库里导入了4w条记录,表有30个字段,有大概10个字段是备注型,存了很多文字
显示有报错
详细错误信息:
调用的目标发生了异常。
引发类型为“System.OutOfMemoryException”的异常。
这种合成sql语句的方式,也会内存溢出吗?
有啥提高的地方不?除了减少一次导入数据量这种方案。