Board index » delphi » search date field in table by using Query ?

search date field in table by using Query ?

i got a problem of searching a date field in the table by using query .

my purpose is to search all the similar date in the table which
can be viewed in the DBGrid .

The following are the properties and setting :

Table1.field is : Input_Date     - which contains the date only

SQL.Tstring = Select* from Report where Input_Date= :Today .

Params.TParams : 'Today' is selected  'Date' in the Data Type.

The following are the code:

Query1.close;
Query1.ParambyName('Today').Asstring := DateEdit1.Text;
Query1.open;
Data Source1.DataSet := Query1;

The following error message appeared  WHEN AFTER entering a date in
DateEdit1.  

Raise exception in class EDBEngine Error with message
'Type mismatch in expression'.

please kindly show any code to avoid this problem ...You are
please to give the detail of some examples or methods

thank you.

 

Re:search date field in table by using Query ?


Quote
fntie wrote:

> i got a problem of searching a date field in the table by using query .

> my purpose is to search all the similar date in the table which
> can be viewed in the DBGrid .

> The following are the properties and setting :

> Table1.field is : Input_Date     - which contains the date only

> SQL.Tstring = Select* from Report where Input_Date= :Today .

> Params.TParams : 'Today' is selected  'Date' in the Data Type.

> The following are the code:

> Query1.close;
> Query1.ParambyName('Today').Asstring := DateEdit1.Text;
> Query1.open;
> Data Source1.DataSet := Query1;

> The following error message appeared  WHEN AFTER entering a date in
> DateEdit1.

> Raise exception in class EDBEngine Error with message
> 'Type mismatch in expression'.

> please kindly show any code to avoid this problem ...You are
> please to give the detail of some examples or methods

> thank you.

Try changing it to

Query1.Close;
Query1.ParambyName('Today').AsDateTime := StrToDate(DateEdit1.Text);
Query1.Prepare;
Query1.Open;
DataSource1.DataSet := Query1;

Re:search date field in table by using Query ?


Since you declared the parameter to be of type Date you need to use
AsDate in the assigment, not AsString.

Bill

(Sorry but TeamB cannot answer support questions received via email.)
(To send me email for any other reason remove .nospam from my address.)

Other Threads