Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open dbase files with different file extensions

Status
Not open for further replies.

skeelz

Programmer
Aug 8, 2007
4
US
Does anyone know how to open dbase files that have different file extensions? We are creating a program that will open and read dbase files and post the information to a database on the internet.

The program that is exporting these dbf files with different extensions is based on very old technology but is the standard throughout the entire collision industry and is the ONLY format collision estimating software uses and exports.

For each job it creates 15 dbase files with different information in them. Instead of making files with different names and .dbf extensions the people who developed the industry standards decided it would be better to name them all the same name with different extensions.

Example:
123456.env
123456.ad1
123456.veh
123456.tot

Basically I need a connection string that will work in visual studio 2005, programming language C#, and open .dbf files with different file extensions.

keep getting the error filename.extension isn't a valid name.


Any help is greatly appreciated!


There is an article on it at microsoft support but it is very old. replacing the # sign didn't work.
Here is the article:

APPLIES TO
• Microsoft Visual Basic 3.0 Professional Edition

The standard file extension used by dBASE for tables is .DBF. In Visual Basic version 3.0 using the dBASE installable ISAMs, you can open a table by specifying the file name without this extension because the dBASE installable ISAM assumes the extension to be .DBF by default. If you specify the extension <filename>.<extension>, the dBASE installable ISAM will not recognize it and will give you the following error message:
<filename>.<extension> isn't a valid name.

To open a dBASE table file that has a non-standard file extension, specify the table name as <filename>#<extension>. The dBASE installable ISAM interprets the pound sign (#) in the table name as a period and opens the dBASE table.
Back to the top

Example
The following code example demonstrates how to open a dBASE table file that has a non-standard file extension (AUTHORS.OLD) and print the first field of all records in the table to the form. The following example assumes that you have a dBASE III table with a file name of AUTHORS.OLD located in the C:\DBASEIII\OLDBOOKS directory. You may need to modify the example and create a dBASE III database with a table called AUTHORS.OLD in order for it to work correctly.

1. Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.
2. Add a Command Button (Command1) to Form1.
3. Add the following code to the Click event of Command1: Sub Command1_Click()
Dim db As Database
Dim OldAuthors As Table

Connect$ = "dBASE III" ' Specify database type
dbName$ = "C:\DBASEIII\OLDBOOKS" ' Specify database directory

Set db = OpenDatabase(dbName$, False, False, Connect$)
Set OldAuthors = db.OpenTable("Authors#Old") ' Open table
While Not OldAuthors.EOF
Print OldAuthors(0) ' Print field(0) to the form
OldAuthors.MoveNext ' for all records.
Wend

OldAuthors.Close
db.Close
End Sub


4. Run the example.
5. Click the Command1 button.

APPLIES TO
• Microsoft Visual Basic 3.0 Professional Edition
 
Hmm, I would take the simple route and use System.IO.File.Copy to copy the original file with the bad extension to a new file name with the proper extension. Provided the extension is the only reason that the file is failing to load.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks for the response, but We don't want to change the file names because we are working with thousands of files and renaming has to be done one at a time.
 
Hi, I am the programmer for the project at hand, maybe I can shed some more light on the subject.

I have tried OleDB, ODBC, ADO and DAO, all open the files just fine as long as they have a ".dbf" extension. The drivers all apparently do not care what extension you put in the code, they only look for .dbf. You can even leave of the extension from the file all together in the code.

Here is a sample of the code I am using..it is in .net but the same principals apply and since this thread is already started I will go ahead and post it here.

The oleDB version

Code:
string conString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + "C:\\Pathways Output" + ";Extended Properties=dBase IV";

            OleDbConnection conn = new OleDbConnection(conString);
            conn.Open();
            DataSet ds = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [0CE52VAI#ENV]", conn);
            da.Fill(ds);
            conn.Close();
            DataTable dt = ds.Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                uniqueFileID = (dr["UNQFILE_ID"].ToStrin());
                
            }//end foreach
            MessageBox.Show(uniqueFileID);
The DAO version, which I hoped would work since it is older technology

Code:
 DAO.DBEngine dbe = new DAO.DBEngine();
            DAO.Workspace ws = dbe.CreateWorkspace("", "admin", "", DAO.WorkspaceTypeEnum.dbUseJet);
            DAO.Database db;
            DAO.Recordset rst;
            string connectType, dbName;

            connectType = "dBASE III";
            dbName = "C:\\Pathways Output";

            db = ws.OpenDatabase(dbName, false, false, connectType);
            rst = db.OpenRecordset("0CE52VAI#ENV",DAO.RecordsetTypeEnum.dbOpenTable,0,DAO.LockTypeEnum.dbOptimistic);
            while (!rst.EOF){
            MessageBox.Show("It Works"); 
            rst.MoveNext(); 
            } 

            rst.Close();
            db.Close();
            ws.Close();
            dbe = null;
I am using the "#" in place of the "." since Microsoft said that would work, however, I get the same result using either.

Thanks for the input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top