|
-
May 11th, 2006, 11:29 AM
#1
Thread Starter
Member
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.
-
May 11th, 2006, 05:30 PM
#2
Thread Starter
Member
-
May 11th, 2006, 06:14 PM
#3
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:
'Connection string template.
Const CONNECTION_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};User Id=admin;Password=;"
'Get all MDB files in the folder.
Dim databaseFiles As String() = IO.Directory.GetFiles("folder path here", "*.mdb")
Dim connection As New OleDbConnection
For Each filePath As String In databaseFiles
'Substitute the actual file path in the template.
connection.ConnectionString = String.Format(CONNECTION_STRING, filePath)
'Connect to and manipulate your database here, then disconnect.
Next filePath
-
May 11th, 2006, 08:14 PM
#4
Thread Starter
Member
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.
-
May 11th, 2006, 08:26 PM
#5
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.
-
May 11th, 2006, 08:28 PM
#6
Thread Starter
Member
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
-
May 11th, 2006, 09:06 PM
#7
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.
-
May 11th, 2006, 09:10 PM
#8
Thread Starter
Member
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...
-
May 11th, 2006, 09:23 PM
#9
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|