delphi数据库开发,动态sql,
delphi数据库开发,动态sql,selectodrbno,delno,pdctno,units,qtyu,delchar,indateFromppcchxxbwher...
delphi数据库开发,动态sql,
select odrbno,delno,pdctno,units,qtyu,delchar,indate From ppcchxxb
where (delno like 'T%' or qtyu<0)
--and indate>='2010-10-01' and indate<='2010-11-02'
and pdctno like '%jm1%'
上面这段代码,我想通过点击窗体上的“查询”按钮,让结果显示在DBGrid1中,
(窗体中以加好DBGrid1,ADOQuery1,DataSource1,等)
“查询”按钮onclick应该怎么写:
像这样子的:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.Sql.Add..................
ADOQuery1.Open; 展开
select odrbno,delno,pdctno,units,qtyu,delchar,indate From ppcchxxb
where (delno like 'T%' or qtyu<0)
--and indate>='2010-10-01' and indate<='2010-11-02'
and pdctno like '%jm1%'
上面这段代码,我想通过点击窗体上的“查询”按钮,让结果显示在DBGrid1中,
(窗体中以加好DBGrid1,ADOQuery1,DataSource1,等)
“查询”按钮onclick应该怎么写:
像这样子的:
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.Sql.Add..................
ADOQuery1.Open; 展开
2个回答
展开全部
var
tmpSql: string;
begin
tmpSql := 'select odrbno,delno,pdctno,units,qtyu,delchar,indate From ppcchxxb ' +
' where (delno like ''T%'' or qtyu<0) and indate>=''2010-10-01''' +
' and indate<=''2010-11-02'' and pdctno like ''%jm1%''';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.Sql.Add(tmpSql)
ADOQuery1.Open;
end;
如果你里边的条件是动态的话,比如时间,则只需将里边的日期换成你选择的比如:
tmpSql := 'select odrbno,delno,pdctno,units,qtyu,delchar,indate From ppcchxxb ' +
' where (delno like ''T%'' or qtyu<0) and indate>=''' +
formatdatetime('yyyy-mm-dd', datetimepicker1.datetime) + '''' +
' and indate<=''2010-11-02'' and pdctno like ''%jm1%''';
tmpSql: string;
begin
tmpSql := 'select odrbno,delno,pdctno,units,qtyu,delchar,indate From ppcchxxb ' +
' where (delno like ''T%'' or qtyu<0) and indate>=''2010-10-01''' +
' and indate<=''2010-11-02'' and pdctno like ''%jm1%''';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.Sql.Add(tmpSql)
ADOQuery1.Open;
end;
如果你里边的条件是动态的话,比如时间,则只需将里边的日期换成你选择的比如:
tmpSql := 'select odrbno,delno,pdctno,units,qtyu,delchar,indate From ppcchxxb ' +
' where (delno like ''T%'' or qtyu<0) and indate>=''' +
formatdatetime('yyyy-mm-dd', datetimepicker1.datetime) + '''' +
' and indate<=''2010-11-02'' and pdctno like ''%jm1%''';
更多追问追答
追问
var
tmpSql: string;
///////////////////////////////为什么定义变量啊,不要定义变量可不可以?
追答
可以~~直接写ADOQuery1.Sql.Add( 'select odrbno,delno,pdctno,units,qtyu,delchar,indate From ppcchxxb ' +
' where (delno like ''T%'' or qtyu=''' +
formatdatetime('yyyy-mm-dd', datetimepicker1.datetime) + '''' +
' and indate<=''2010-11-02'' and pdctno like ''%jm1%''');
就可以了
展开全部
adoquery1.sql.text := 'select odrbno,delno,pdctno,units,qtyu,delchar,indate From ppcchxxb
where (delno like '''+'T'+'%'' or qtyu<0)
--and indate>=''2010-10-01'' and indate<=''2010-11-02''
and pdctno like ''%'+'jm1'+'%''';
where (delno like '''+'T'+'%'' or qtyu<0)
--and indate>=''2010-10-01'' and indate<=''2010-11-02''
and pdctno like ''%'+'jm1'+'%''';
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询