一个数据库查询问题。(100分)

  • 主题发起人 主题发起人 lanse
  • 开始时间 开始时间
L

lanse

Unregistered / Unconfirmed
GUEST, unregistred user!
各位帮帮忙!本人不大懂SQL查询语句。今天做程序碰到了一个问题:
Query1.Close;
Query1.SQL.Clear;
query1.SQL.Add('select * from P_RuKu.db where ComeDate>'+''''+DateTimePicker1.Date+'''');
query1.Prepare;
query1.ExecSQL;
query1.Open;
if query1.RecNo=0 then
Application.MessageBox('在此时间段没有找到记录!', '信息......',MB_OK+MB_ICONASTERISK);
编译通过了,但实际运行有问题。
觉得query1.SQL.Add('select * from P_RuKu.db where ComeDate>'+''''+DateTimePicker1.Date+'''');这句
语法上就有问题。请帮我把正确的写下好吗?
 
query1.SQL.Add('select * from P_RuKu.db where ComeDate>'+DateTimePicker1.Date+')';
 

Query1.Close;
Query1.SQL.Clear;
query1.SQL.Add('select * from P_RuKu.db where ComeDate>'+''''+DateTimePicker1.Date+'''');
query1.Prepare; //去掉
query1.ExecSQL; //去掉
query1.Open;
 
query1.SQL.Add('select * from P_RuKu.db where ComeDate>'+''''+DateTimeToStr(DateTimePicker1.Date)+'''');
 
query1.SQL.Add('select * from P_RuKu.db where ComeDate>'+
DateToStr(DateTimePicker1.Date));
 
query1.SQL.Add('select * from P_RuKu.db where ComeDate>"'+DateTimePicker1.Date+"')';
 
Query1.SQL.Clear;
query1.SQL.Add('select * from P_RuKu.db where ComeDate>:mydate');
query1.parambyname('mydate').asdate:=datetimepicker1.date;
Query1.SQL.open;

 
有参数吧
Query1.Close;
Query1.SQL.Clear;
query1.SQL.Add('select * from P_RuKu.db where ComeDate>:datepick');
query1.params[0].asdatetime:=DateTimePicker1.Date ;
query1.Prepare;
query1.open;
注:datepick是参数
 
Query1.Close;
Query1.SQL.Clear;
query1.SQL.Add('select * from P_RuKu.db where ComeDate>'+DateToStr(DateTimePicker1.Date));
query1.Open;
if query1.RecordCount=0 then
Application.MessageBox('在此时间段没有找到记录!', '信息......',MB_OK+MB_ICONASTERISK);
//并没有变换DateTimePicker1,用参数多此一举。
 
if Query1.Active Then Query1.Close;
Query1.SQL.Clear;
query1.SQL.Add('select * from P_RuKu.db where ComeDate>'''+DateTimePicker1.Date+'''');
query1.Open;
//变量应用'''+变量名+'''来表示
 
execsql 当QUERY的操作不返回结果
OPEN 当QUERY的操作只返回结果
 
谢谢各位的帮忙!
 
后退
顶部