1

我正在尝试运行以下代码来访问文件夹中的 DBF 文件。如果是 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
            }

并执行以下查询:

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
                            }

问题是执行查询时会出现以下错误:

Microsoft Jet 数据库引擎找不到对象“RF10.DBF”。确保对象存在并且正确拼写其名称和路径名。

但是,存在一个名为 RF10.dbf 的文件。我哪里错了?

4

3 回答 3

2

IIRC您没有在查询中包含扩展名:

fpcmd.CommandText = "SELECT * FROM RF10 WHERE SRNO='RDDFT000108'";
于 2013-10-31T13:49:45.437 回答
1

尝试使用完整的文件路径:

fpcmd.CommandText = "SELECT * FROM 'D:\some_folder\RF10.DBF' WHERE SRNO='RDDFT000108'";
于 2013-10-31T13:47:45.777 回答
0

这可能是您对文件夹或文件的访问权限。你检查过吗?

于 2013-10-31T13:44:50.840 回答