Solved

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

Posted on 2004-09-16
5
4,689 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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