| View previous topic :: View next topic |
| Author |
Message |
David Guest
|
Posted: Wed Dec 24, 2003 3:39 am Post subject: Re: passing date parameter in commandtext |
|
|
SamiraInStL <samirastl (AT) earthlink (DOT) net> wrote
| Quote: | datas is from Access 2000 and it shows the whole table in my DBGrid.
I enter 2 date string in Edit1 and Edit2 control.
How do I pass the date parameter to commandtext in AdoDataset ?
adodataset.commandtext := 'select id, PayDate from tblPayment where
payDate
= ' + edit1.text + 'and payDate <=' + edit2.text ; // this does not work
Please help
somner
I am not familiar with Access, but the other SQLs I use require that the |
date be in mm/dd/yyyy format. Is edit1.text and exit2.text in that format?
David
|
|
| Back to top |
|
 |
David Guest
|
Posted: Wed Dec 24, 2003 3:40 am Post subject: Re: passing date parameter in commandtext |
|
|
David <dfm (AT) cmgasia (DOT) com.hk> wrote
| Quote: |
SamiraInStL <samirastl (AT) earthlink (DOT) net> wrote in message
news:3fe90a18$1 (AT) newsgroups (DOT) borland.com...
datas is from Access 2000 and it shows the whole table in my DBGrid.
I enter 2 date string in Edit1 and Edit2 control.
How do I pass the date parameter to commandtext in AdoDataset ?
adodataset.commandtext := 'select id, PayDate from tblPayment where
payDate
= ' + edit1.text + 'and payDate <=' + edit2.text ; // this does not
work
Please help
somner
I am not familiar with Access, but the other SQLs I use require that the
date be in mm/dd/yyyy format. Is edit1.text and exit2.text in that
format?
David
Sorry, the dates must be ' delimited as well (I use quotedstr()) |
|
|
| Back to top |
|
 |
anonymous Guest
|
Posted: Wed Dec 24, 2003 9:44 am Post subject: Re: passing date parameter in commandtext |
|
|
yes, you must trans the date
"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote
| Quote: | Try it using parameters. That way date conversion will take place in your
code
and you don't have to worry about the date format the query accepts
adodataset.commandtext := 'select id, PayDate from tblPayment where
payDate
= :date1 'and payDate <= :Date2' // this does not work
AdoDataset.parameters.parambyName('Date1') := StrToDate(Edit1.text)
AdoDataset.parameters.parambyName('Date2') := StrToDate(Edit2.text)
--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]
|
|
|
| Back to top |
|
 |
Alexander Zuev Guest
|
Posted: Wed Dec 24, 2003 2:14 pm Post subject: Re: passing date parameter in commandtext |
|
|
| Quote: | datas is from Access 2000 and it shows the whole table in my DBGrid.
I enter 2 date string in Edit1 and Edit2 control.
How do I pass the date parameter to commandtext in AdoDataset ?
adodataset.commandtext := 'select id, PayDate from tblPayment where
payDate
= ' + edit1.text + 'and payDate <=' + edit2.text ; // this does not work
|
In your case try this way:
adodataset.commandtext := 'select id, PayDate from tblPayment where payDate
| Quote: | =" ' + edit1.text + ' " and payDate <= " ' + edit2.text+' " ' ;
|
The better method is:
adodataset.commandtext := 'select id, PayDate from tblPayment where payDate
| Quote: | = :PayDate and payDate <= :PayDate ' ;
And then assign adodataset's paremeter "PayDate" with needful value. |
|
|
| Back to top |
|
 |
Benny Joseph Guest
|
Posted: Sat Jan 03, 2004 1:24 pm Post subject: Re: passing date parameter in commandtext |
|
|
SamiraInStL wrote:
| Quote: | datas is from Access 2000 and it shows the whole table in my DBGrid.
I enter 2 date string in Edit1 and Edit2 control.
How do I pass the date parameter to commandtext in AdoDataset ?
adodataset.commandtext := 'select id, PayDate from tblPayment where
payDate
= ' + edit1.text + 'and payDate <=' + edit2.text ; // this does
not work
Please help
somner
|
Hi,
As everybody suggested using parameter is the best option. But when you
use direct assignment I believe that you have to use something like:
ADODataset.CommandText := 'Select id, PayDate From tblPayment Where
PayDate >= #' + Edit1.Text + '# And PayDate <= #' + Edit2.Text + '#';
And date must be in 'MM/dd/yyyy' format.
Regards,
Benny Joseph
Capital Soft Pvt. Ltd.
|
|
| Back to top |
|
 |
|