[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-09-16
5
Medium Priority
?
4,877 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

829 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