BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: passing date parameter in commandtext

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
David
Guest





PostPosted: Wed Dec 24, 2003 3:39 am    Post subject: Re: passing date parameter in commandtext Reply with quote




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





PostPosted: Wed Dec 24, 2003 3:40 am    Post subject: Re: passing date parameter in commandtext Reply with quote



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





PostPosted: Wed Dec 24, 2003 9:44 am    Post subject: Re: passing date parameter in commandtext Reply with quote



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





PostPosted: Wed Dec 24, 2003 2:14 pm    Post subject: Re: passing date parameter in commandtext Reply with quote

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





PostPosted: Sat Jan 03, 2004 1:24 pm    Post subject: Re: passing date parameter in commandtext Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.