Results 1 to 9 of 9

Thread: DBF help

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    57

    DBF help

    All mighty VB guru's,
    I need your help again. I have a directory with multiple DBF files. I want to write a program that opens each DBF file and insert a column into the table. After that i need that column to be populate with the filename of where the table (all the tables will be merged later on to create one big table)... is this possible? Where do i begin from?

    Using VB.NET 2003
    Last edited by Phantom7; May 11th, 2006 at 05:46 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    57

    Re: DBF help

    anyone...

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DBF help

    You would have to use IO.Directory.GetFiles to get a list of all DBF files in your folder. You would then loop through those and insert the file name into a template connection string. You can then connect to that database and do what you want with its data. You close the connection and then the loop moves on to the next file. I don't know what database DBF files are for but here's an example of what you would do if they were MDB files:
    VB Code:
    1. 'Connection string template.
    2.         Const CONNECTION_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};User Id=admin;Password=;"
    3.  
    4.         'Get all MDB files in the folder.
    5.         Dim databaseFiles As String() = IO.Directory.GetFiles("folder path here", "*.mdb")
    6.  
    7.         Dim connection As New OleDbConnection
    8.  
    9.         For Each filePath As String In databaseFiles
    10.             'Substitute the actual file path in the template.
    11.             connection.ConnectionString = String.Format(CONNECTION_STRING, filePath)
    12.  
    13.             'Connect to and manipulate your database here, then disconnect.
    14.         Next filePath
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    57

    Re: DBF help

    not sure i'm understanding the code right...the DBF file is just a simple database. I want to create a program that opens the DBF and add a column into the table. Then the program needs to populate the column with the source file name (the name of the file it came from beofre i merge them into the one large table...this is mainly for referencing)...thats all I really need it to do. I understand the portion IO.Directory.GetFiles but i'm not sure how to have it edit the table
    Last edited by Phantom7; May 11th, 2006 at 08:19 PM.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DBF help

    What do you mean by "a simple database file"? Are you saying that it is a file of your own creation with a format defined by you? If not, what database format does it use? For example MDB files are Microsoft Access format, while MDF files are SQL Server format. You have to know something about the format of any file in order to interact with it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    57

    Re: DBF help

    actually they are from someone else....All i want is to add the new field in each of the files (there are alot of them) so that when the files are merged that there will be a reference point

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DBF help

    Well if you aren't going to tell us anything about the file format then how can we help? Has it been created with a real database program or is it just a binary data file? If it's a real database then you'd use ADO.NET. If it's not then you'll have to use an IO class to access and manipulate it, like BinaryReader and BinaryWriter.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    57

    Re: DBF help

    sorry... i miss uderstood the question... It's created with a database program.. not sure which one... The files opens fine in excel..... I've never done anything like this...never done anything with ADO either...

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DBF help

    Well you need to find out what database program they were created with so you know how to connect to them. If you're going to interact with databases from .NET apps then you need to learn at least the basics of SQL and ADO.NET. There are links to tutorials on each in my signature.

    ADO.NET connects to every data source in almost exactly the same way, but there are some differences, the most notable being the connection string. This contains information about the type of database and how the connection should be made. Virtually everything else is the same for all data sources and is handled behind the scenes by ADO.NET and the database itself.

    www.connectionstrings.com has details of connection string format for numerous data sources, including DBF it appears. Apparently you use almost exactly the same as I provided previously for MDB files.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width