Domanda

I am trying to run the following code to access a DBF file in folder. the name of the file if RF10.dbf:

 foxpro = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\xxxxxx\\xxxxx\\xxxxx\\;Extended Properties=dBASE IV;User ID=ADMIN;Password=;");


            try
            {
                foxpro.Open();
                label4.Text = "Connected";
            }
            catch (OleDbException oex)
            {
                label4.Text = "Connection Failed";
                //  connection error
            }

And executing following query:

OleDbCommand fpcmd = new OleDbCommand();
                            fpcmd.Connection = foxpro;
                            fpcmd.CommandText = "SELECT * FROM RF10.DBF WHERE SRNO='RDDFT000108'";
                            fpcmd.CommandType = CommandType.Text;
                            fpcmd.CommandTimeout = 300;



                            try
                            {
                                acompressor = (String)fpcmd.ExecuteScalar();
                                // SqlDataAdapter da = new SqlDataAdapter(cmd1);
                                //DataSet ds = new DataSet();
                                // da.Fill(ds);
                                if (acompressor == null)
                                    acompressor = "";


                                if (acompressor.Equals(compressor))
                                {
                                    MessageBox.Show("Serial number and compressor number is a correct match.");
                                    textBox1.Text = "";
                                    textBox2.Text = "";
                                }
                                else
                                {

                                    MessageBox.Show("Serial number and compressor number DO NOT match.");
                                    textBox1.Text = "";
                                    textBox2.Text = "";
                                }
                            }
                            catch (OleDbException oex)
                            {
                                Console.Write(fpcmd.CommandText);
                                Console.Write(oex.Message);
                                //   command related or  other  exception
                            }

The problem is when the query is executed it gives the following error:

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

However, there exist a file named RF10.dbf. Where am I going wrong?

È stato utile?

Soluzione 3

It might be your access rights to the folder or file. Have you checked that?

Altri suggerimenti

IIRC you don't include the extension in the query:

fpcmd.CommandText = "SELECT * FROM RF10 WHERE SRNO='RDDFT000108'";

Try to use the full file path:

fpcmd.CommandText = "SELECT * FROM 'D:\some_folder\RF10.DBF' WHERE SRNO='RDDFT000108'";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top