Jump to content

bulk insert of 3142 rows, only inserts exactly 200

- - - - -

  • Please log in to reply
1 reply to this topic

#1
doubleotwo

doubleotwo

    Newbie

  • Members
  • PipPip
  • 10 posts
Context:
Large txt delimited file needs to be inserted into table db...

I got a snippet of code on the internet of a bulk insert which works good except for the amount...
i dont actually know where the problem lies, at my code or the db...

this is my code


Dim dt As New DataTable()

        Dim line As String = Nothing

        Dim i As Integer = 0

        Dim c As Integer = 0


        Using sr As StreamReader = File.OpenText(strFilePath)

            c = c + 1


            line = sr.ReadLine()


            'SKIP COLUMNS

            'If c = 1 Then

            'line = sr.ReadLine()

            'End If


            Do While line IsNot Nothing



                Dim data() As String = line.Split(Delimiter.ToCharArray())

                If data.Length > 0 Then

                    If i = 0 Then

                        For Each itemx In data

                            dt.Columns.Add(New DataColumn())

                        Next itemx

                        i += 1

                    End If

                    Dim row As DataRow = dt.NewRow()

                    row.ItemArray = data

                    dt.Rows.Add(row)

                End If

                line = sr.ReadLine()

            Loop

        End Using

'when i watch my dt, its show count for rows = 3142, which is correct


'only insert remoteid , just to test this

Using cn As New SqlConnection(pConstring)

            cn.Open()

            Using copy As New SqlBulkCopy(cn)

                copy.ColumnMappings.Add(New SqlBulkCopyColumnMapping(1, "remoteid"))

                'copy.ColumnMappings.Add(1, 1)

                'copy.ColumnMappings.Add(2, 2)

                'copy.ColumnMappings.Add(3, 3)

                'copy.ColumnMappings.Add(4, 4)

                copy.DestinationTableName = "tblklanten"

                copy.WriteToServer(dt)

            End Using

        End Using


thx alot for all your advice

#2
PsychoCoder

PsychoCoder

    Learning Programmer

  • Members
  • PipPipPip
  • 92 posts
Ok do you get any errors or anything?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users