procedure TForm1.Button1Click(Sender: TObject);
var sql:string;yy,:integer;
begin
yy:=strtoint(Edit1.Text);
sql:='select * from pipe_mapinfo where pipe_num=yy' ;//这有什么错?Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add(sql);
Query1.Prepare;
Query1.Active:=true;
end;
我如果有两个Edit2.Text,Edit3.Text 输入时间范围,又该怎么写?和Edit1.Text一起组成复合条件查询?怎么写?

解决方案 »

  1.   

    sql:='select * from pipe_mapinfo where pipe_num=yy' 改成
    sql:='select * from pipe_mapinfo where pipe_num='''+yy+'''';
      

  2.   

    是sql:='select * from pipe_mapinfo where pipe_num='''+IntToStr(yy)+'''';
      

  3.   

    sql:='select * from pipe_mapinfo where pipe_num=yy' 改成
    sql:='select * from pipe_mapinfo where pipe_num='+IntToStr(yy)+'';
      

  4.   

    同意楼上,
    多条件也一样
    sql:='select * from pipe_mapinfo where pipe_num='''+IntToStr(yy)+'''';
    sql := sql + ' 日期字段  between ''''+edit2.text+''''+ and + '''' edit3.text'''';
      

  5.   

    sql:='select * from pipe_mapinfo where (pipe_num='+IntToStr(yy)+')'
        +'and(YourDate>FormatDate('yyyy-mm-dd',StrToDate(Edit2.Text)))'
        +'and(YourDate<FormatDate('yyyy-mm-dd',StrToDate(Edit3.Text)))';
    这里的pipe_num是Integer类型的.