Date Parameters conversion error

4 posts, 0 answers
  1. Clifford
    Clifford avatar
    2 posts
    Member since:
    Dec 2011

    Posted 16 Feb 2012 Link to this post

    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?

  2. Hadib Ahmabi
    Hadib Ahmabi avatar
    181 posts
    Member since:
    Nov 2011

    Posted 17 Feb 2012 Link to this post

    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 
  3. Matt
    Matt avatar
    3 posts
    Member since:
    Feb 2012

    Posted 01 Mar 2012 Link to this post

    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;




    HighDurCharge_spTableAdapter adapter = new HighDurChargeTableAdapters.HighDurCharge_spTableAdapter();




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




    Report)sender).DataSource = data1.AsDataView;



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


  4. Elian
    Elian avatar
    435 posts

    Posted 02 Mar 2012 Link to this post

    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.

    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.
Back to Top