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

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

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

Try
        con.ConnectionString = v_ObjConn

        Dim ParamName(8), ParamType(8), ParamValue(8) As String

        ParamName(0) = "@WOCODE" : ParamType(0) = SqlDbType.VarChar
        ParamName(1) = "@WODESC" : ParamType(1) = SqlDbType.VarChar
        ParamName(2) = "@WOTYPE" : ParamType(2) = SqlDbType.VarChar
        ParamName(3) = "@TAGNUMBER" : ParamType(3) = SqlDbType.VarChar

        ParamName(4) = "@PMCODE" : ParamType(4) = SqlDbType.VarChar
        ParamName(5) = "@STATUS" : ParamType(5) = SqlDbType.VarChar
        ParamName(6) = "@COMPLETEDDATE" : ParamType(6) = SqlDbType.Date
        ParamName(7) = "@LASTUPDATE" : ParamType(7) = SqlDbType.Date

        lblWaitingMsg.Text = "Importing records into the VAIL-Plant. Please wait..."

        For Each row As GridViewRow In gv_InforWO.Rows

            Dim chkBoxSelect As CheckBox = CType(row.FindControl("chkSelect"), CheckBox)

            If chkBoxSelect.Checked = True Then

                ParamValue(0) = row.Cells(1).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
                ParamValue(1) = row.Cells(2).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
                ParamValue(2) = row.Cells(3).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
                ParamValue(3) = row.Cells(4).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)

                ParamValue(4) = row.Cells(5).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
                ParamValue(5) = row.Cells(6).Text.ToString().Replace("&", "and").Replace(" ", String.Empty)
                ParamValue(6) = Convert.ToDateTime(row.Cells(7).Text)
                ParamValue(7) = Convert.ToDateTime(row.Cells(8).Text)

                Func.SP_ExecDML(con, "[dbo].[SP_InsertWorkOrders_InforEAM]", ParamName, ParamType, ParamValue)

            End If

        Next

        MsgBox("Records have been imported/updated.")

        BindGridInfoWO()

    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        lblWaitingMsg.Text = ""
    End Try

暂无答案!

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

相关问题