C#中的错误DBF文件读取器

时间:2012-06-08 13:28:37

标签: c# dbf

错误:查询中出现语法错误。不完整的查询条款。 请帮帮我。

        string db_file = null;
        OpenFileDialog op = new OpenFileDialog();
        op.InitialDirectory = Application.StartupPath + "\\out";
        op.Filter = "DBF file|*.dbf"; 
        if (op.ShowDialog() == DialogResult.OK)
        {
            db_file = op.FileName;
            FileInfo fi = new FileInfo(op.FileName);

                   String ConnectionString;
                   ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fi.DirectoryName + ";Extended Properties=dBase 5.0;Mode=Read|Write|Share Deny None;Persist Security Info=True";
          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 * From '" + Path.GetFileNameWithoutExtension(fi.Name) + "'", dBaseConnection);
          System.Data.OleDb.OleDbDataReader dBaseDataReader;
          dBaseDataReader = dBaseCommand.ExecuteReader();
          while (dBaseDataReader.Read()) 
          {
              MessageBox.Show("x");
          }
          dBaseDataReader.Close();   

错误:查询中出现语法错误。不完整的查询条款。

2 个答案:

答案 0 :(得分:0)

试试这个:

("Select * From " + Path.GetFileNameWithoutExtension(fi.Name) , dBaseConnection)

没有引号'路径..'。

希望它有所帮助。

答案 1 :(得分:0)

我建议使用VfpOleDb provider。以下是使用该提供程序的连接字符串:

ConnectionString = "Provider=VfpOleDb;Data Source=" + fi.DirectoryName;