|
-
Jul 10th, 2007, 03:43 PM
#8
Thread Starter
PowerPoster
Re: read dbase(dbf) files...OleDB?
Ok, I found some slighty different code and it seems to work fine except for one issue. It disregards the file extension on the file and only looks for .dbf.
For instance, if I have 4 files all named File1 except with different extensions it doesn't work. These are all dbase files, just named with program specific extensions. Each group of files are related to eachother like tables in a database.
I guess me question is..how do I open and read a dbase file that doesn't have a .dbf extension?
For example the folder I am pulling the files from might look like this
File1.env
File1.ptf
File1.lpa
File1.ttp
File2.env
File2.ptf
File2.lpa
File2.ttp
File3.env
File3.ptf
File3.lpa
File3.ttp
Each group of files share the same file name, but have different extensions.
Is there any way I can get this code to actualy open the exact file I specify? Like if I put "SELECT * FROM File1.env" it says that file cannot be found..but if I rename the file to File1.dbf it finds it just fine.
I can even put "SELECT * FROM File1" and as long as there is a File1.dbf in there it will read it, but with any other extension it won't.
I know it is possible to do because I have seen a couple of other programs that do it, but I am at a loss. Maybe I need to use a different driver?
Anyway, here is the code I am using.
Code:
string conString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\EMS FILES\\;Extended Properties=dBase IV";
OleDbConnection conn = new OleDbConnection(conString);
conn.Open();
// create the DataSet
DataSet ds = new DataSet();
// create the adapter and fill the DataSet
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM UF01J1RU.env", conn);
adapter.Fill(ds);
conn.Close();
//spit out data
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
MessageBox.Show(dr["LBR_TYPE"].ToString());
}//end for
Thanks!
Last edited by Arc; Jul 10th, 2007 at 05:04 PM.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

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
|