ERROR [42000] [Microsoft][ODBC Visual FoxPro Driver]Command contains unrecognized phrase/keyword.代码如下:
private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = "选择dbf文件";
            openFileDialog1.Filter = "dbf文件(*.dbf)|*.dbf";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                conn = new OdbcConnection();
                string filePath = Path.GetDirectoryName(openFileDialog1.FileName);
                string connStr = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + filePath + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO";
                conn.ConnectionString = connStr;
                conn.Open();
                string sql = "select * from " + openFileDialog1.FileName;
                OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);
                ds = new DataSet();
                da.Fill(ds);//此处报错
                int col = ds.Tables[0].Columns.Count;
                for (int i = 0; i < col; i++)
                {
                    comboBox1.Items.Add(ds.Tables[0].Columns[i].ColumnName);
                    comboBox2.Items.Add(ds.Tables[0].Columns[i].ColumnName);
                }
                comboBox1.SelectedIndex = 0;
                comboBox2.SelectedIndex = 0;
            }    
        }

解决方案 »

  1.   

                int s = -1;
                string fileName = openFileDialog1.FileName;
                for (int i = openFileDialog1.FileName.Length - 1; i >= 0; i--)
                {
                    if (fileName[i] == '\\')
                    {
                        s = i;
                        break;
                    }
                }            if (s != -1)
                {
                    string sql = "select * from " + fileName.Substring(s + 1, fileName.Length - 4 - (s + 1));
                    //..........
                }
      

  2.   

    找到原因啦 读取的文件路径中不能带有空格 比如“c:\Document and Settings\桌面\abc.dbf” 就不行。
      

  3.   

    和着说:"select * from c:\windows\abc.dbf"这句语句也可以正常执行?好象有的版本的FoxPro不可以,上例必须用"select * from abc",至少这有个老程序就不可以.
      

  4.   


    SourceDB=c:\windows\abc.dbf 而不是sql语句"select * from c:\windows\abc.dbf"