string excelname=wangyu;
string DBFtable = textBox2.Text.Trim();//dbf数据库
System.Data.Odbc.OdbcConnection DBFconn = new System.Data.Odbc.OdbcConnection(@"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + DBFtable + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO");
DBFconn.Open();
OdbcCommand DBFcmd = DBFconn .CreateCommand();
DBFcmd.CommandText="Selcet Xm From +DBFtable Where Xm=excelname";
OdbcDataReader DBFReader=DBFcmd .ExecuteReader ();
DBFReader .Read ()为什么没值呢?请大侠帮忙看一下!谢谢!
                    

解决方案 »

  1.   

    "Selcet Xm From +DBFtable Where Xm=excelname",这里面的+DBFtable什么东西,你把它放到sql里面肯定不行,应该放到""号外部,拼接成完整的sql
      

  2.   


    Xm是字段,DBFtable是数据库文件,
    这样的如何写才可以?
    多谢!
      

  3.   

    "Selcet Xm From +DBFtable Where Xm=excelname",
    应该把+DBFtable改为表名称 
      

  4.   

    但这数据库和excelname是个变量,如何操作?
      

  5.   

    "Selcet Xm From" +DBFtable "Where Xm="+excelname;
     这样也不可以
      

  6.   

    string excelname=wangyu;
    string DBFtable = textBox2.Text.Trim();//路径下的dbf数据库
    System.Data.Odbc.OdbcConnection DBFconn = new System.Data.Odbc.OdbcConnection(@"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + DBFtable + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO");
    DBFconn.Open();
    OdbcCommand DBFcmd = DBFconn .CreateCommand();
    DBFcmd.CommandText="Select * From“ +DBFtable+ "Where Xm="+excelname;
    OdbcDataReader DBFReader=DBFcmd .ExecuteReader ();
    这样也不可以执行,什么原因呢?