数据库是access  ,请问我这条sql 语句怎么行不通呢? 
Var
 Sql_Str:String;
 D1,D2:TDateTime;
begin
  D1:=DBeginDate.DateTime ;
  D2:=EEndDate.DateTime;
  Sql_Str:='Select Code_id  Code_Type ,Frim_id , Pro_Name from BaseInfo 
        Where Apply_Date between :D1 and :D2 ';
  if Trim(CodeN.Text)<>'' then
    Sql_Str:=Sql_Str+' and Code_id like ''%'+CodeN.Text+'%''';
  if Trim(CodeType.Text)<>'' then
    Sql_Str:=Sql_Str+' and Code_Type like ''%'+CodeType.Text+'%''';
  if Trim(CorPoration.Text)<>'' then
    Sql_Str:=Sql_Str+' and CorPoration  like ''%'+CorPoration.Text+'%''';
  if Trim(FrimEdt.Text)<>'' then
    Sql_Str:=Sql_Str+' and Frim_id Like ''%'+FrimEdt.Text+'%''';
  Sql_Str:=Sql_Str+' order by Code_id ';
  With  DM.InsertInfoQue  do
    begin
      Close;
      Sql.Clear;
      Sql.Add(Sql_Str);
      Parameters.ParamByName('D1').Value:=Min(D1, D2);
      Parameters.ParamByName('D2').Value:=Max(D1, D2);
      Open;
    end;

解决方案 »

  1.   

    你不要贴代码,直接将最后生成的Sql_Str贴出来就很明了了。
      

  2.   

    第一:第7行,select code_id后面应加","
    第二:试试将apply_date between :d1 and :d2 改为 apply_date>=:d1 and apply_date<=:d2。 或者将between放到语句的最后。
      

  3.   

    调试的时候,你在DM.InsertInfoQue的open之加showmessage(Sql_Str);
    仔细看一下Sql_Str就很清楚了
      

  4.   

    Sql_Str:=Sql_Str+' and Code_id like like :CodeVar ';
    {...}
    Parameters.ParamByName('CodeVar').Value := '%'+trim(CodeN.Text)+'%';(注:Like句也写成参数方式)
      

  5.   

    Sorry, 上述SQL句多了一個likeSql_Str:=Sql_Str+' and Code_id like :CodeVar ';
      

  6.   

    with ADOQuery1 do begin
       {...}
        Parameters.Clear;
        Parameters.AddParameter.Name := 'D1';
        Parameters.AddParameter.Name := 'D2';
        Parameters.ParamByName('D1').DataType := ftTime;  //定義類型試試
        Parameters.ParamByName('D2').DataType := ftTime;
       {...}
    end;
      

  7.   

    cronuz(cronus) ( ) 信誉:100 
    为什么要这样做呢?
      

  8.   

    在TADOQuery中定義参数名時、要明確定義参数類型...
      

  9.   

    showmessage(sql_str) 把的到的结果贴出来看看