那张帖子30分,还是没有解决问题。100分吧,希望能得到解决!!!原帖子地址:
http://community.csdn.net/Expert/topic/4987/4987851.xml?temp=.9855158
procedure TSarch.FormCreate(Sender: TObject);
begin
datetimepicker1.Date:=now();
datetimepicker2.Date:=now();
edit1.Clear;
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER); RZcombobox1.Clear;
with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select distinct model from Common ');
open;
end;
if data1.Sarch.RecordCount>0 then
begin
while not data1.Sarch.Eof do
begin
rzcombobox1.Items.Add(data1.Sarch.fieldbyname('model').AsString);
data1.Sarch.Next;
end;
end;// 列出生产线 / / with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select distinct line from Common ');
open;
end;
if data1.Sarch.RecordCount>0 then
begin
while not data1.Sarch.Eof do
begin
rzcombobox3.Items.Add(data1.Sarch.fieldbyname('line').AsString);
data1.Sarch.Next;
end;
end;
with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select distinct class from Common ');
open;
end;
if data1.Sarch.RecordCount>0 then
begin
while not data1.Sarch.Eof do
begin
rzcombobox4.Items.Add(data1.Sarch.fieldbyname('class').AsString);
data1.Sarch.Next;
end;
end; // 列出班次 with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select distinct shift from Common ');
open;
end;
if data1.Sarch.RecordCount>0 then
begin
while not data1.Sarch.Eof do
begin
rzcombobox2.Items.Add(data1.Sarch.fieldbyname('shift').AsString);
data1.Sarch.Next;
end;
end;
with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select shift from common');
open;
end; end;
procedure TSarch.BitBtn1Click(Sender: TObject); var
i:integer;
low,high:string;
begin
s:='select * from information ';
i:=0;
if Rzcombobox1.Text<>'' then
begin if i=0 then
s:=s+' where model='''+Rzcombobox1.Text+''''
else
s:=s+' and model='''+Rzcombobox1.Text+'''';
i:=i+1;
end;
if Edit1.Text<>'' then
begin
if i=0 then
s:=s+' where sampleID='''+Edit1.Text+''''
else
s:=s+' and sampleID='''+Edit1.Text+'''';
i:=i+1;
end; if Rzcombobox2.Text<>'' then
begin if i=0 then
s:=s+' where shift='''+Rzcombobox2.Text+''''
else
s:=s+' and shift='''+Rzcombobox2.Text+'''';
i:=i+1;
end;
if Rzcombobox3.Text<>'' then
begin if i=0 then
s:=s+'where line='''+Rzcombobox3.Text+''''
else
s:=s+' and line='''+Rzcombobox3.Text+'''';
i:=i+1;
end;
if Rzcombobox4.Text<>'' then
begin if i=0 then
s:=s+' where grade='''+Rzcombobox4.Text+''''
else
s:=s+' and grade='''+Rzcombobox4.Text+'''';
i:=i+1;
end; if Rzcombobox5.Text<>'' then
begin if i=0 then
s:=s+' where parts='''+Rzcombobox5.Text+''''
else
s:=s+' and parts='''+Rzcombobox5.Text+'''';
i:=i+1;
end; low:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
high:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
if i=0 then
s:=s+'where '
else
s:=s+' and ';
s:=s+'workdate<'''+high+''' and workdate>'''+low+'''';
ADOQuery1.Connection:=ADOConnection1;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(s);
ADOQuery1.Open;end;
这段代码错在那里?
-------------------------------------------------------- low:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
high:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
if i=0 then
s:=s+'where '
else
s:=s+' and ';
s:=s+'workdate<'''+high+''' and workdate>'''+low+'''';
---------------------同过两个datatimepicker1 和datatimepicker1 查询某一段日期类的记录。程序编译能通过,但是一旦提交“查询”,就报错“标准表达试中类型不匹配”
什么原因?要如何写?还有什么办法可以实现这个功能?
http://community.csdn.net/Expert/topic/4987/4987851.xml?temp=.9855158
procedure TSarch.FormCreate(Sender: TObject);
begin
datetimepicker1.Date:=now();
datetimepicker2.Date:=now();
edit1.Clear;
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER); RZcombobox1.Clear;
with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select distinct model from Common ');
open;
end;
if data1.Sarch.RecordCount>0 then
begin
while not data1.Sarch.Eof do
begin
rzcombobox1.Items.Add(data1.Sarch.fieldbyname('model').AsString);
data1.Sarch.Next;
end;
end;// 列出生产线 / / with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select distinct line from Common ');
open;
end;
if data1.Sarch.RecordCount>0 then
begin
while not data1.Sarch.Eof do
begin
rzcombobox3.Items.Add(data1.Sarch.fieldbyname('line').AsString);
data1.Sarch.Next;
end;
end;
with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select distinct class from Common ');
open;
end;
if data1.Sarch.RecordCount>0 then
begin
while not data1.Sarch.Eof do
begin
rzcombobox4.Items.Add(data1.Sarch.fieldbyname('class').AsString);
data1.Sarch.Next;
end;
end; // 列出班次 with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select distinct shift from Common ');
open;
end;
if data1.Sarch.RecordCount>0 then
begin
while not data1.Sarch.Eof do
begin
rzcombobox2.Items.Add(data1.Sarch.fieldbyname('shift').AsString);
data1.Sarch.Next;
end;
end;
with data1.Sarch do
begin
close;
sql.Clear;
sql.Add('select shift from common');
open;
end; end;
procedure TSarch.BitBtn1Click(Sender: TObject); var
i:integer;
low,high:string;
begin
s:='select * from information ';
i:=0;
if Rzcombobox1.Text<>'' then
begin if i=0 then
s:=s+' where model='''+Rzcombobox1.Text+''''
else
s:=s+' and model='''+Rzcombobox1.Text+'''';
i:=i+1;
end;
if Edit1.Text<>'' then
begin
if i=0 then
s:=s+' where sampleID='''+Edit1.Text+''''
else
s:=s+' and sampleID='''+Edit1.Text+'''';
i:=i+1;
end; if Rzcombobox2.Text<>'' then
begin if i=0 then
s:=s+' where shift='''+Rzcombobox2.Text+''''
else
s:=s+' and shift='''+Rzcombobox2.Text+'''';
i:=i+1;
end;
if Rzcombobox3.Text<>'' then
begin if i=0 then
s:=s+'where line='''+Rzcombobox3.Text+''''
else
s:=s+' and line='''+Rzcombobox3.Text+'''';
i:=i+1;
end;
if Rzcombobox4.Text<>'' then
begin if i=0 then
s:=s+' where grade='''+Rzcombobox4.Text+''''
else
s:=s+' and grade='''+Rzcombobox4.Text+'''';
i:=i+1;
end; if Rzcombobox5.Text<>'' then
begin if i=0 then
s:=s+' where parts='''+Rzcombobox5.Text+''''
else
s:=s+' and parts='''+Rzcombobox5.Text+'''';
i:=i+1;
end; low:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
high:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
if i=0 then
s:=s+'where '
else
s:=s+' and ';
s:=s+'workdate<'''+high+''' and workdate>'''+low+'''';
ADOQuery1.Connection:=ADOConnection1;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(s);
ADOQuery1.Open;end;
这段代码错在那里?
-------------------------------------------------------- low:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
high:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
if i=0 then
s:=s+'where '
else
s:=s+' and ';
s:=s+'workdate<'''+high+''' and workdate>'''+low+'''';
---------------------同过两个datatimepicker1 和datatimepicker1 查询某一段日期类的记录。程序编译能通过,但是一旦提交“查询”,就报错“标准表达试中类型不匹配”
什么原因?要如何写?还有什么办法可以实现这个功能?
high:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
if i=0 then
s:=s+'where '
else
s:=s+' and ';
s:=s+'workdate<'''+high+''' and workdate>'''+low+'''';
---------------------
这段代码有问题吗?要如何写?重要能功能实现,用什么办法都可以,谢谢
adoquery1.parameters.ParamByName('col1').Value := FormatDateTime('yyyy-mm-dd',DateTimepicker1.Date);
adoquery1.parameters.ParamByName('col2').Value := FormatDateTime('yyyy-mm-dd',DateTimepicker1.Date);
adoquery1.open
begin
mStr := 'select * from information where ';
s := '';
if Rzcombobox1.Text<>'' then
s:=s+'model='''+Rzcombobox1.Text+''' and '; if Edit1.Text<>'' then
s:=s+'sampleID='''+Edit1.Text+''' and '; if Rzcombobox2.Text<>'' then
s:=s+'shift='''+Rzcombobox2.Text+''' and '; if Rzcombobox3.Text<>'' then
s:=s+line='''+Rzcombobox3.Text+''' and '; if Rzcombobox4.Text<>'' then
s:=s+'grade='''+Rzcombobox4.Text+''' and '; if Rzcombobox5.Text<>'' then
s:=s+'parts='''+Rzcombobox5.Text+''' and '; low:=formatdatetime('yyyy-mm-dd',DateTimePicker2.Date);
high:=formatdatetime('yyyy-mm-dd',DateTimePicker2.Date);
s:=mStr + s + 'workdate<'''+high+''' and workdate>'''+low+'''';
ADOQuery1.Connection:=ADOConnection1;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(s);
ADOQuery1.Open;end;
怎么改?
var mStr:string;
var low,high:string;
begin
mStr := 'select * from information where ';
s := '';
if Rzcombobox1.Text<>'' then
s:=s+'model='''+Rzcombobox1.Text+''' and '; if Edit1.Text<>'' then
s:=s+'sampleID='''+Edit1.Text+''' and '; if Rzcombobox2.Text<>'' then
s:=s+'shift='''+Rzcombobox2.Text+''' and '; if Rzcombobox3.Text<>'' then
s:=s+'line='''+Rzcombobox3.Text+''' and '; if Rzcombobox4.Text<>'' then
s:=s+'grade='''+Rzcombobox4.Text+''' and '; if Rzcombobox5.Text<>'' then
s:=s+'parts='''+Rzcombobox5.Text+''' and '; low:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker1.Date);
high:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
s:=mStr + s + 'workdate<'''+high+''' and workdate>'''+low+'''';
ADOQuery1.Connection:=ADOConnection1;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(s);
ADOQuery1.Open;end;
改成这样,还是不行。 糊涂了~~~~~~~~~~
high:=formatdatetime('yyyy"-"mm"-"dd',DateTimePicker2.Date);
s:=mStr + s + 'workdate<'''+high+''' and workdate>'''+low+'''';
这几句没改啊!!
low:=formatdatetime('yyyy-mm-dd',DateTimePicker2.Date);
high:=formatdatetime('yyyy-mm-dd',DateTimePicker2.Date);
s:=mStr + s + 'workdate<#'+high+'# and workdate>#'+low+'#';
如果是sql server 改成
low:=formatdatetime('yyyy-mm-dd',DateTimePicker2.Date);
high:=formatdatetime('yyyy-mm-dd',DateTimePicker2.Date);
s:=mStr + s + 'workdate<'''+high+''' and workdate>'''+low+'''';
high:=formatdatetime('yyyy-mm-dd',DateTimePicker2.Date);
s:=mStr + s + 'workdate<#'+high+'# and workdate>#'+low+'#';
-------------------------------------------------------------------
s:=mStr + s + 'workdate<#'+high+'# and workdate>#'+low+'#'; s:=mStr + s + 'workdate<'''+high+''' and workdate>'''+low+'''';
这两句的异同之处是什么?谢谢!!!
access的时间要用#括起来,仅此而已。