如何使用vb.net快速地将数百万条记录一次插入到sql表中?

xj3cbfub  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(456)

我正在用数据填充gridview,并使用只有insert语句的存储过程将记录逐个插入sql表中。
这是可以的,但当记录是以百万计,那么这需要相当长的时间。我想快速地插入表格,不需要太多时间。

  1. Try
  2. con.ConnectionString = v_ObjConn
  3. Dim ParamName(8), ParamType(8), ParamValue(8) As String
  4. ParamName(0) = "@WOCODE" : ParamType(0) = SqlDbType.VarChar
  5. ParamName(1) = "@WODESC" : ParamType(1) = SqlDbType.VarChar
  6. ParamName(2) = "@WOTYPE" : ParamType(2) = SqlDbType.VarChar
  7. ParamName(3) = "@TAGNUMBER" : ParamType(3) = SqlDbType.VarChar
  8. ParamName(4) = "@PMCODE" : ParamType(4) = SqlDbType.VarChar
  9. ParamName(5) = "@STATUS" : ParamType(5) = SqlDbType.VarChar
  10. ParamName(6) = "@COMPLETEDDATE" : ParamType(6) = SqlDbType.Date
  11. ParamName(7) = "@LASTUPDATE" : ParamType(7) = SqlDbType.Date
  12. lblWaitingMsg.Text = "Importing records into the VAIL-Plant. Please wait..."
  13. For Each row As GridViewRow In gv_InforWO.Rows
  14. Dim chkBoxSelect As CheckBox = CType(row.FindControl("chkSelect"), CheckBox)
  15. If chkBoxSelect.Checked = True Then
  16. ParamValue(0) = row.Cells(1).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
  17. ParamValue(1) = row.Cells(2).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
  18. ParamValue(2) = row.Cells(3).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
  19. ParamValue(3) = row.Cells(4).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
  20. ParamValue(4) = row.Cells(5).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
  21. ParamValue(5) = row.Cells(6).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
  22. ParamValue(6) = Convert.ToDateTime(row.Cells(7).Text)
  23. ParamValue(7) = Convert.ToDateTime(row.Cells(8).Text)
  24. Func.SP_ExecDML(con, "[dbo].[SP_InsertWorkOrders_InforEAM]", ParamName, ParamType, ParamValue)
  25. End If
  26. Next
  27. MsgBox("Records have been imported/updated.")
  28. BindGridInfoWO()
  29. Catch ex As Exception
  30. MsgBox(ex.Message)
  31. Finally
  32. lblWaitingMsg.Text = ""
  33. End Try

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题