hi Miles,
thank you for the file.
Assume VB2005, Visual Fox Pro OleDb Driver
Free download:
http://www.microsoft.com/downloads/d...displaylang=en
[install the exe, minimal ok, no reboot needed]
Assume a Form1 with DataGridView1 and ToolStripStatus Label1
Posting here (slightly improved version) so that other can propose
improvements (very welcome). If need VB2003 or have problems just let
me know....
-tommaso
[Datatime Free Project]
'----------------------------------------------------------------------------
Imports System.Data.Ole Db
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Me.ToolStripSta tusLabel1.Text = String.Empty
Dim InputFileName As String
Dim d As New OpenFileDialog
With d
.Filter = "VFP files (*.dbf)|*.dbf|A ll files (*.*)|*.* "
If Not d.ShowDialog.Eq uals(Windows.Fo rms.DialogResul t.OK)
Then Exit Sub
InputFileName = .FileName
.Dispose()
End With
If Me.DoDBFProcess (InputFileName) Then
Me.ToolStripSta tusLabel1.Text = "Records read OK"
End Sub
Private Function DoDBFProcess(By Val InputFileName As String, _
Optional ByVal MaxNumRecordToR ead As
Integer = Integer.MaxValu e) As Boolean
Dim DataTableRecord s As New DataTable
Dim Connection As New OleDbConnection
Try
With Connection
.ConnectionStri ng = "Provider=VFPOL EDB.1;Data Source="
& InputFileName & ";Mode=Read|Sha re Deny None;Collating
Sequence=MACHIN E"
.Open()
End With
Catch ex As Exception
MsgBox(ex.Messa ge)
Return False
End Try
Dim Sequential As Integer = 0
Try
Using OleDbCommandREA D As New OleDbCommand("S elect * from
revfilef", Connection)
Using OleDbDataReader As OleDbDataReader =
OleDbCommandREA D.ExecuteReader ()
DataTableRecord s = New DataTable
For i As Integer = 0 To OleDbDataReader .FieldCount
- 1
DataTableRecord s.Columns.Add(N ew
DataColumn(OleD bDataReader.Get Name(i),
OleDbDataReader .GetFieldType(i )))
Next i
Dim Values(OleDbDat aReader.FieldCo unt - 1) As
Object 'record distinti
While OleDbDataReader .Read()
Sequential += 1
If Sequential > MaxNumRecordToR ead Then Exit
While
OleDbDataReader .GetValues(Valu es)
DataTableRecord s.Rows.Add(Valu es)
End While
Me.ToolStripSta tusLabel1.Text = Sequential & "
records read through " & Connection.Prov ider
End Using
End Using
Me.DataGridView 1.DataSource = DataTableRecord s
Return True
Catch ex As Exception
MsgBox(ex.Messa ge & vbCrLf & vbCrLf)
Return False
Finally
Connection.Clos e()
End Try
End Function
End Class