?
Solved

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

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

771 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