Solved

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

Posted on 2004-09-16
5
4,518 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
Comment Utility
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
Comment Utility
change provider to ..
provider=VFPOLEDB.1
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
Comment Utility
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
Comment Utility
Bob,

Thanks a lot

Gregory
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

12 Experts available now in Live!

Get 1:1 Help Now