Home > Back-end >  How do you write this according to the date of the query parameterized queries?
How do you write this according to the date of the query parameterized queries?

Time:04-26


ADOQuery1. SQL. The Add (' Select * From Student ');//query students table
ADOQuery1. SQL. The Add (' Where the Birthdate BETWEEN ' ' '+ DateToStr (DateTimePicker1. Date) +' 00:00:00 ' 'AND' ' '+ DateToStr (DateTimePicker2. Date) +' 23:59:59 '");//query in this range of date of birth
ADOQuery1. Open;

CodePudding user response:

 
ADOQuery1. SQL. The Add (' Select * From Student ');//query students table
ADOQuery1. SQL. The Add (' Where the Birthdate BETWEEN: vDate1 AND: vDate2 ');
//DataType setting parameter type
ADOQuery1. The Parameters. ParamByName (' vDate1). DataType:=TFieldType. FtDateTime;
ADOQuery1. The Parameters. ParamByName (' vDate1). Value:=DateTimePicker1. Date;
ADOQuery1. The Parameters. ParamByName (' vDate2). DataType:=TFieldType. FtDateTime;
//IncDay is date plus one day
ADOQuery1. The Parameters. ParamByName (' vDate2). Value:=IncDay (DateTimePicker2. Date);

CodePudding user response:

reference 1st floor tanqth response:
 
ADOQuery1. SQL. The Add (' Select * From Student ');//query students table
ADOQuery1. SQL. The Add (' Where the Birthdate BETWEEN: vDate1 AND: vDate2 ');
//DataType setting parameter type
ADOQuery1. The Parameters. ParamByName (' vDate1). DataType:=TFieldType. FtDateTime;
ADOQuery1. The Parameters. ParamByName (' vDate1). Value:=DateTimePicker1. Date;
ADOQuery1. The Parameters. ParamByName (' vDate2). DataType:=TFieldType. FtDateTime;
//IncDay is date plus one day
ADOQuery1. The Parameters. ParamByName (' vDate2). Value:=IncDay (DateTimePicker2. Date);

This line can't perform the past
ADOQuery1. The Parameters. ParamByName (' vDate1). DataType:=TFieldType. FtDateTime;

CodePudding user response:

Always feel you have a problem string
ADOQuery1. SQL. The Add (' Where the Birthdate BETWEEN '+ DateToStr (DateTimePicker1. Date) +' 00:00:00. 000 '+' AND '+ DateToStr (DateTimePicker2. Date) +' 23:59:59. 999 ');
You have a try, or check the returned string is correct,

CodePudding user response:

ADOQuery1. SQL. The Add (' Where the Birthdate BETWEEN '+ quotedstr (DateToStr (DateTimePicker1. Date)) +' 00:00:00. 000 '+' AND '+ quotedstr (DateToStr (DateTimePicker2. Date)) +' 23:59:59. 999 ');

CodePudding user response:

ADOQuery1. SQL. The Add (' Where the Birthdate BETWEEN '+ quotedstr (DateToStr (DateTimePicker1. Date) +' 00:00:00. 000 ') + 'AND' + quotedstr (DateToStr (DateTimePicker2. Date) + '23:59:59. 999'));
Do I also have a little dizzy, roughly is so, you give it a try, ha ha ha

CodePudding user response:

refer to the second floor of NEEZA which zha reply:
Quote: refer to 1st floor tanqth response:
 
ADOQuery1. SQL. The Add (' Select * From Student ');//query students table
ADOQuery1. SQL. The Add (' Where the Birthdate BETWEEN: vDate1 AND: vDate2 ');
//DataType setting parameter type
ADOQuery1. The Parameters. ParamByName (' vDate1). DataType:=TFieldType. FtDateTime;
ADOQuery1. The Parameters. ParamByName (' vDate1). Value:=DateTimePicker1. Date;
ADOQuery1. The Parameters. ParamByName (' vDate2). DataType:=TFieldType. FtDateTime;
//IncDay is date plus one day
ADOQuery1. The Parameters. ParamByName (' vDate2). Value:=IncDay (DateTimePicker2. Date);

This line can't perform the past
ADOQuery1. The Parameters. ParamByName (' vDate1). DataType:=TFieldType. FtDateTime;


What tips?
Don't just say "no" "wrong" "there is a problem," to say what, what tips, what's wrong
  • Related