在我的三层结构的客户端有一个DbGrid1连着dm.CDSPntBasic(Clientdataset):
dm.CDSPntBasic.CommandText := '';
dm.CDSPntBasic.CommandText:='select * from PntBasic where replace(DEPTNAME,'+'''' + ' '+'''' + ',' + ''''+''''+') = '+''''+aaa+'''';
dm.CDSPntBasic.Execute;
dm.CDSPntBasic.Open;
dm.CDSPntBasic.Active := true;问题是:
如果Sql语句里没有where语句,就可以返回数据集, 而加上where语句(如上)后返回为空数据集。为什么?
谢谢大家!!!!!!!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    你的WHERE 条件肯定是错误的
    仔细检查:调试吧
      

  2.   

    用Ms Profiler 之類的, 檢查你提交到後台的查詢語句有沒有問題
      

  3.   

    说的没错!
    dm.CDSPntBasic.CommandText:='select * from PntBasic where DEPTNAME='+''''+'外科'+'''';
    以上可以执行,但以下就返回为空:
    aaa:='外科';
    dm.CDSPntBasic.CommandText:='select * from PntBasic where DEPTNAME='+''''+aaa+'''';我只是用变量aaa 代替了'外科',可结果就是不行,为什么???
      

  4.   

    dm.CDSPntBasic.CommandText:='select * from PntBasic where DEPTNAME='''+aaa+''''
    这样试一试