日期:2014-05-19  浏览次数:20805 次

关于返回查询结果的问题
string   cc   =   textBox28.Text.ToString().Trim();
OdbcConnection   myConn2   =   new   OdbcConnection( "Driver={Microsoft   Visual   FoxPro   Driver}; "   +
  "SourceType=DBF; "   +   "SourceDB=d:\\2007; "   +   "Exclusive=No; ");
string   cxsql   =   "select   *   from   dwdm.dbf   where   dwdm= ' "   +   cc   +   " ' ";
                       
                        OdbcCommand   thisconmand   =   new   OdbcCommand(cxsql,   myConn);
                       
现在想知道查到几条结果(主要是有没有的问题)
如果用int   i=thisconmand.ExecuteNonQuery();返回都是-1,看了下msdn,只有用update之类的才会返回选中的行数。。。



------解决方案--------------------
string cxsql = "select count(*) from .... ";
...
int i=(int)thisconmand.ExecuteScalar();
------解决方案--------------------
断点看一下thisconmand.ExecuteScalar();返回什么
------解决方案--------------------
select count(*).....的执行结果是需要的行数就存储在第一行第一列,调用ExecuteScalar()即可得到。