This is a migrated thread and some comments may be shown as answers.

Date Parameters conversion error

3 Answers 589 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Clifford
Top achievements
Rank 2
Clifford asked on 16 Feb 2012, 10:47 PM
New to these specific reporting controls, and that "ah ah" moment just hasn't arrived. Creating the class for a report, generating the datasource, setting up the parameters makes sense but getting it to work with parameters in designer is eluding me. I want to pass in a "begin" and "end" date for the data I pull, so I've set up the parameters in the datasource as @dtstrDate and @dtendDate, with DbType as Date and the Value as "=Parameters.startDate.Value" and "= Parameters.endDate.Value" respectively.

The query:

SELECT        w.Firstname, w.Lastname, wf.Login, wf.Logout, DATEDIFF(hour, wf.Login, wf.Logout) AS Hours
FROM            Workers AS w INNER JOIN
                       Workflow AS wf ON wf.LoggedInWorkerid = w.ID
WHERE        (wf.Login >= @dtstrtDate) AND (wf.Logout <= @dtendDate)


I've tested it in SQL Server with

DECLARE @dtstrtDate AS DateTime
SET @dtstrtDate = '02/13/2012'
DECLARE @dtendDate AS DateTime
SET @dtendDate = '02/17/2012'
 
SELECT w.Firstname, w.Lastname, SUM(DATEDIFF(hour, wf.Login, wf.Logout)) AS Hours
FROM Workers AS w JOIN Workflow AS wf ON wf.LoggedInWorkerid = w.ID
WHERE wf.Login >= @dtstrtDate AND wf.Logout <= @dtendDate
GROUP BY w.Lastname, w.FirstName


... and it works just fine.

In the Configure DataSource Parameters
Name                   DbType                     Value
@dtstrtDate         Date                          =Parameters.startDate.Value
@dtendDate        Date                          =Parameters.endDate.Value

Design Time Parameters
Name                 Value
@dtstrtDate       =02/13/2012 (and I've tried putting these values in single quotes as well)
@dtendDate      =02/17/2012

I've tried setting the DbType to string, as well on the designer, setting the startDate and endDate members in the ReportParameter collection to DateTime and String, and even using the CDate function to wrap the Parameters.startDate.Value i.e = CDate(Parameters.startDate.Value)...When I try to execute the query in the designer I get "Conversion failed when converting date/and or time from character string." What am I doing incorrectly?


3 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 17 Feb 2012, 12:26 PM
Try with:
In the Configure DataSource Parameters
Name                   DbType                     Value
@dtstrtDate         DateTime                          =Parameters.startDate.Value
@dtendDate        DateTime                          =Parameters.endDate.Value

Design Time Parameters
Name                 Value
@dtstrtDate       02/13/2012 (without '=' and quotes)
@dtendDate      02/17/2012 
0
Matt
Top achievements
Rank 1
answered on 01 Mar 2012, 08:00 PM
I am having simialr issue but not sure i am doing this wrong we are trying to deside if we are going to use this product and this is a big show stopper.  Also why can't i debug to the error?  i.e code so i can see whats being passed:

 

 

private void Report1_NeedDataSource(object sender, EventArgs e)

 

{

 

 

string name1 = (string)this.ReportParameters["Property"].Value;

 

 

 

string class1 = (string)this.ReportParameters["Class"].Value;

 

 

 

double duration = (double)this.ReportParameters["Duration"].Value;

 

 

 

decimal Charge = (decimal)this.ReportParameters["Charge"].Value;

 

 

 

DateTime StartDate = Convert.ToDateTime(((string)this.ReportParameters["FromDate"].Value + " " + (string)this.ReportParameters["FromTime"].Value));

 

 

 

DateTime EndDate = Convert.ToDateTime(((string)this.ReportParameters["ToDate"].Value + " " + (string)this.ReportParameters["ToTime"].Value));

 

 

 

string Type1 = (string)this.ReportParameters["Type"].Value;

 

HighDurChargeTableAdapters.

 

HighDurCharge_spTableAdapter adapter = new HighDurChargeTableAdapters.HighDurCharge_spTableAdapter();

 

 

 

HighDurCharge.HighDurCharge_spDataTable data1 = adapter.GetData(name1, class1, StartDate, EndDate, Type1, duration, Charge);

 

((Telerik.Reporting.Processing.

 

Report)sender).DataSource = data1.AsDataView;

 

}

I need this quick or we will have to find another product.

thanks,

matthew.majerus@xeta.com

0
Elian
Telerik team
answered on 02 Mar 2012, 03:21 PM
Hello Matt,

Each Telerik Report is just a standard class that you can debug the same way you can debug any other class from your project. Just create a new instance of the report in code and the debugger will hit the breakpoint in the constructor. You can also add a report viewer to your web page, specify a report for it, and the report constructor will be called as soon as you try to preview this report in the page. 

From the description you provided we couldn't fully understand what is the problem you are experiencing. If it is retrieving the data from the Report parameters, please review the following article : Using Report Parameters programmatically.

Greetings,
Elian
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Tags
General Discussions
Asked by
Clifford
Top achievements
Rank 2
Answers by
Hadib Ahmabi
Top achievements
Rank 1
Matt
Top achievements
Rank 1
Elian
Telerik team
Share this question
or