WINFORM程序
ACCESS数据库
表名 table1
记录 共六条 如下  ID        taxno        taxname          datetime
1         123456        abcdef          2009-9-10
2         123456        abcdef          2009-9-10
3         123456        abcdef          2009-9-10
4         123456        abcdef          2009-9-10
5                       abcdef          2009-9-10
6                       abcdef          2009-9-10执行语句 string sql11 = "select count('"+table1key +"') from table1 group by  '"  + table1key + "' having count("+"'"+table1key+"'"+")>1";string sql12 = "select count(*) from table1 where '" +  table1key +"' is null";说明:table1key为一个COMBOX组件当前选定的值,即表中taxno,taxname中的任一项,程序中以选择taxno为例问题描述:在程序中执行上述语句时第一个语句的值为6,第二个为0,但是把语句中的参数table1key换成实际的列名,在ACCESS中执行时,结果则为正确的4和2请各位达人给指点一下,问题出现在哪里?

解决方案 »

  1.   

    把单引号去掉string sql11 = "select count("+table1key +") from table1 group by  "  + table1key + " having count("+ table1key +")>1";string sql12 = "select count(*) from table1 where " +  table1key +" is null"; 
      

  2.   

    第一条语句,Count()直是栏位,不是字符变量,所以要去掉引号:
    string sql11 = "select count("+table1key +") from table1 group by  "  + table1key + " having count("+"+table1key+")>1"; 
    第二条语句,如果语句值不是空,而是空字符,会没数据,同时也不要引号,所以用IsNull()函数好,改为:
    string sql12 = "select count(*) from table1 where IsNull(" +  table1key +",'')=''"