Hello everybody,
I am having problems in connecting dbf file using C#

Actually, what i want to do is as follows:

1. on GO button, the code connects to dbf file saved in my local hdd ie at d:\dbase
2. the file name is billingsample.dbf of type IV
3. the file contains 4 columns, one is account_no and another is a num_poles
4. after connection to the dbf file the code should search the account_no column and print the first row in it at text2.text

here is the code

private void button1_Click(object sender, EventArgs e)
        {
            String ConnectionString;
            ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source = D:\\dbase;Extended Properties =dBase IV;";
            System.Data.OleDb.OleDbConnection dBaseConnection;
            dBaseConnection = new System.Data.OleDb.OleDbConnection(ConnectionString);
            dBaseConnection.Open();
            System.Data.OleDb.OleDbCommand dBaseCommand;
            dBaseCommand = new System.Data.OleDb.OleDbCommand("SELECT ACCOUNT_NO FROM billingsample", dBaseConnection);
            System.Data.OleDb.OleDbDataReader dBaseDataReader;
            dBaseDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess);
            
               textBox2.Text=dBaseDataReader.GetValue(0).ToString();
           }

but the following codes give error

The Microsoft Jet database engine could not find the object 'billingsample'. Make sure the object exists and that you spell its name and the path name correctly


I tried changing the string SELECT ACCOUNT_NO from billingsample to billingsample.dbf or d:\\dbase\\billingsample

but i have no sucess .....:(


Any help wuld be appreciatd

Are you aware that the Jet engine is very picky about the dBase file version. This is why I prefer to use the ODBC classes instead of Ole.

I had a similar problem using your code, and after switching it out to use ODBC, everything worked fine, and even a little faster.. go figure.

// Jerry

Hi,

I had the same problem ... you found a solution?
thanks for your help

After much frustration, trying different connection strings.... It turns out the file name of the data file was too long. Apparently the file cannot have more than 8(?) characters in it's name otherwise the connection will fail and the file cannot be found.

Gotta say, that's about the stupidest crap ever.

It's the filename. The extension has to be .DBF. If it's anything else, it won't work. I've been trying to find a solution for it to read a file like FILE.XYZ. Anyone with an answer?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.