title: Bulk importing text files / VB2005 / SQL Server 2005
body: <p>I've inherited a .NET app to support / enhance which reads in a couple of files of high hundreds of thousands of rows, and one of millions of row.</p>
  
  <p>The original developer left me code like :-</p>
  
  <pre><code>                For Each ModelListRow As String In ModelListDataArray
                      If ModelListRow.Trim.Length = 0 Or ModelListRow.Contains(",") = False Then
                          GoTo SKIP_ROW
                      End If
  
                      Dim ModelInfo = ModelListRow.Split(",")
                      Dim ModelLocation As String = UCase(ModelInfo(0))
                      Dim ModelCustomer As String = UCase(ModelInfo(1))
                      Dim ModelNumber As String = UCase(ModelInfo(2))
  
                      If ModelLocation = "LOCATION" Or ModelNumber = "MODEL" Then
                          GoTo SKIP_ROW
                      End If
  
                      Dim MyDataRow As DataRow = dsModels.Tables(0).NewRow
                      MyDataRow.Item("location") = ModelLocation.Replace(vbCr, "").Replace(vbLf, "").Replace(vbCrLf, "")
                      MyDataRow.Item("model") = ModelNumber.Replace(vbCr, "").Replace(vbLf, "").Replace(vbCrLf, "")
                      dsModels.Tables(0).Rows.Add(MyDataRow)
  SKIP_ROW:
                  Next
  </code></pre>
  
  <p>and it takes an age (well, nearly half an hour) to import these files.</p>
  
  <p>I suspect there's a MUCH better way to do it. I'm looking for suggestions.</p>
  
  <p>Thanks in advance.</p>