Import DBF in SQL server via VB.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

What's the best way to upload a dbf file into SQL server? the code I'm using
works, but give because of the timeduration a server time out. the file has
approx. 14000 rows

below you'll find the code I've used
Thx for your quick response

If DialogResult.OK = Windows.Forms.DialogResult.OK And
OpenFileDialog1.FileName <> "" Then

Dim pl As Int16 = OpenFileDialog1.FileName.LastIndexOfAny("\")
Dim p As String = OpenFileDialog1.FileName.Substring(0, pl)

MsgBox("de NEWPROD data wordt geïmporteerd, gelieve even te
wachten", MsgBoxStyle.Critical)

Dim c As New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & p &
";Extended Properties=dBASE IV;User ID=Admin;Password=;")

c.Open()

Dim com As New OleDbCommand("select * from NEWPROD", c)
com.Connection = c
Dim myAdapter As New OleDbDataAdapter

myAdapter.SelectCommand = com

Dim myDS As New DataSet
myAdapter.Fill(myDS)

Dim da As New SolTableAdapters.NEWPRODTableAdapter
Dim ds As New Sol.NEWPRODDataTable

da.DeleteQuery()

For Each r As DataRow In myDS.Tables(0).Rows
Try
Dim rij As DataRow = ds.NewRow
rij("id") = r.Item("id").ToString

If IsNumeric(r.Item("UNIT_PRICE").ToString) Then
rij("UNIT_PRICE") = r.Item("UNIT_PRICE").ToString
If IsNumeric(r.Item("RETAIL").ToString) Then
rij("RETAIL") = r.Item("RETAIL").ToString
rij("DESC") = r.Item("DESC").ToString
rij("PLID") = r.Item("plid").ToString
If IsNumeric(r.Item("WEIGHT").ToString) Then
rij("WEIGHT") = r.Item("WEIGHT").ToString

ds.Rows.Add(rij)
Catch ex As Exception

End Try

Next

Try
da.Update(ds)
 
Back
Top