3

ERROR: Syntax error in query. Incomplete query clause. Please help me.

        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();   

ERROR: Syntax error in query. Incomplete query clause.

4

2 回答 2

0

Try this:

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

without the quotes 'Path..'.

Hope it helps.

于 2012-06-08T13:31:59.177 回答
0

I would suggest using the VfpOleDb provider. Here is the connection string using that provider:

ConnectionString = "Provider=VfpOleDb;Data Source=" + fi.DirectoryName;
于 2012-06-08T14:03:49.697 回答