Solved

How to read a FoxPro dbf file structure in VB.NET ?

Posted on 2004-09-16
5
4,559 Views
Last Modified: 2012-02-01
Hi,

I am writing a VB.NET application that reads data from dbf files (FoxPro).

I need a possibility to read a structure of a dbf file (column names and their types).

In FoxPro, for example, it can be achived by using LIST STRUCTURE command or
afields() function.

How can I do the same in VB.NET program ?

Regards,


Gregory
0
Comment
Question by:GregBo
  • 2
  • 2
5 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 12074692
you will need to connect to ADO.net with the string somethung like this....

Provider=MSDASQL;Persist Security Info=False;Extended Properties=Driver={Microsoft Visual FoxPro Driver};UID=;SourceDB=c:\temp\mydb.dbf;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;
0
 
LVL 27

Expert Comment

by:planocz
ID: 12074762
change provider to ..
provider=VFPOLEDB.1
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 12076450
This is what I use:

  Public Function GetLogFileFields(ByVal folderName As String) As DataColumnCollection

    ' Build a connection string to the FoxPro free table folder.
    Dim connectionString As String = "Provider=VFPOLEDB.1;Data Source=" & folderName

    ' Create a connection to the tables.
    Dim connectFoxPro As OleDbConnection = New OleDbConnection(connectionString)

    ' Select all the fields from the log file.
    Dim queryString As String = "Select * From LogFile"
    Dim commandLogFile As OleDbCommand = New OleDbCommand(queryString, connectFoxPro)

    Dim readerFoxPro As OleDbDataReader

    Dim tableSchema As DataTable

    Try

      ' Open the connection to the table directory.
      connectFoxPro.Open()

      ' Get a DataReader to retrieve table information.
      readerFoxPro = commandLogFile.ExecuteReader

      ' Get the schema from the DataReader.
      tableSchema = readerFoxPro.GetSchemaTable()

    Catch ex As Exception

      MessageBox.Show(ex.ToString)

    End Try

    ' Return the column collection from the table schema.
    Return tableSchema.Columns

    If Not connectFoxPro Is Nothing Then

      If connectFoxPro.State = ConnectionState.Open Then
        connectFoxPro.Close()
      End If

      connectFoxPro.Dispose()

    End If

    If Not commandLogFile Is Nothing Then

      commandLogFile = Nothing

      commandLogFile.Dispose()

    End If

    If Not tableSchema Is Nothing Then
      tableSchema = Nothing
    End If

    If Not readerFoxPro Is Nothing Then
      readerFoxPro.Close()
      readerFoxPro = Nothing
    End If

  End Function 'GetLogFileFields'


Call with:

    Dim colsLogFile As DataColumnCollection = GetLogFileFields("WhiteBoard")

Bob
0
 

Author Comment

by:GregBo
ID: 12083806
Bob,

Thanks a lot

Gregory
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12083988
Since it appears that you are fairly new to E-E:

Closing Questions
http://www.experts-exchange.com/help.jsp#hi5

Bob
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now