none
Get milliseconds from DateTime report parameter

    Question

  • To simplify the situation, let's say I have a report, in which I pass a DateTime parameter. The value is with milliseconds. This al works well, the milliseconds are in the report subsystem and can be seen on the report.

    Now I need to fetch that parameter's value in code. When doing so, the only option I'm aware of is to use

    ReportParameterInfoCollection.Item("MyDateTime").Values.First()

    which happily delivers me a string. As the default string representation of DateTime lacks milliseconds, I loose them, so I can't compare to the previously stored list with milliseconds.

    Question: how can I get the DateTime report parameter with milliseconds from my code?


    Mikhail

    Monday, August 19, 2013 12:37 PM

All replies

  • Hi Mikhail,

    Thank you for your question. 

    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 

    Thank you for your understanding and support.

    Regards,
    Charlie Liao

    If you have any feedback on our support, please click here.

    Charlie Liao
    TechNet Community Support

    Tuesday, August 20, 2013 8:42 AM
  • Hi,

    Check if this code can help you: http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.reportparameterinfo%28v=vs.100%29.aspx

    What is your report type (RDL or RDLC)?

    Can you provide complete code and sample report and sample table for what you want to do?


    Regards,
    Christian HL
    Microsoft Online Community Support


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Tuesday, August 20, 2013 9:17 AM
  • The code also uses "string" and has no notion of special DateTime treatment. So no news there.

    The report I use is RDLC. I'll see if I have the time by next week to create a sample project.


    Mikhail

    Tuesday, August 20, 2013 10:23 AM
  • Hi,

    The very simple case is that I pass a DateTime to report as a parameter, and milliseconds get lost.

    Project generated from "Reports Application" template.

    Code (remember to correct path in reportDoc.Load):

    Imports System.Xml
    Imports System.IO
    Imports Microsoft.Reporting.WinForms
    
    
    Public Class FormMain
    
    	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    		Dim reportDoc As New XmlDocument()
    
    		reportDoc.Load("c:\users\mni\documents\visual studio 2012\Projects\ReportTimeMilliseconds\ReportTimeMilliseconds\ReportTime.rdlc")
    
    		Using outputStream As New StringReader(reportDoc.OuterXml)
    			ReportViewer1.LocalReport.LoadReportDefinition(outputStream)
    		End Using
    
    		Dim dt = New DateTime(2013, 9, 16, 11, 58, 12, 135)
    		ReportViewer1.LocalReport.SetParameters(
    			New ReportParameter("Time", CStr(Convert.ChangeType(dt, GetType(String))), False))
    
    		Me.ReportViewer1.RefreshReport()
    	End Sub
    
    End Class
    The probably bizzare conversion in SetParameters is because the original code uses generics to set parameters.

    Report (XML):

    <?xml version="1.0" encoding="utf-8"?>
    <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
      <Body>
        <ReportItems>
          <Textbox Name="Textbox1">
            <CanGrow>true</CanGrow>
            <KeepTogether>true</KeepTogether>
            <Paragraphs>
              <Paragraph>
                <TextRuns>
                  <TextRun>
                    <Value>Time parameter:</Value>
                    <Style />
                  </TextRun>
                </TextRuns>
                <Style />
              </Paragraph>
            </Paragraphs>
            <rd:DefaultName>Textbox1</rd:DefaultName>
            <Height>0.6cm</Height>
            <Width>2.92333cm</Width>
            <Style>
              <Border>
                <Style>None</Style>
              </Border>
              <PaddingLeft>2pt</PaddingLeft>
              <PaddingRight>2pt</PaddingRight>
              <PaddingTop>2pt</PaddingTop>
              <PaddingBottom>2pt</PaddingBottom>
            </Style>
          </Textbox>
          <Textbox Name="Textbox2">
            <CanGrow>true</CanGrow>
            <KeepTogether>true</KeepTogether>
            <Paragraphs>
              <Paragraph>
                <TextRuns>
                  <TextRun>
                    <Value>=CDate(Parameters!Time.Value).ToString("hh\:mm\:ss.fff")</Value>
                    <Style />
                  </TextRun>
                </TextRuns>
                <Style />
              </Paragraph>
            </Paragraphs>
            <rd:DefaultName>Textbox2</rd:DefaultName>
            <Left>2.92333cm</Left>
            <Height>0.6cm</Height>
            <Width>3.42604cm</Width>
            <ZIndex>1</ZIndex>
            <Style>
              <Border>
                <Style>None</Style>
              </Border>
              <PaddingLeft>2pt</PaddingLeft>
              <PaddingRight>2pt</PaddingRight>
              <PaddingTop>2pt</PaddingTop>
              <PaddingBottom>2pt</PaddingBottom>
            </Style>
          </Textbox>
        </ReportItems>
        <Height>0.23622in</Height>
        <Style />
      </Body>
      <Width>6.5in</Width>
      <Page>
        <PageHeight>29.7cm</PageHeight>
        <PageWidth>21cm</PageWidth>
        <LeftMargin>2cm</LeftMargin>
        <RightMargin>2cm</RightMargin>
        <TopMargin>2cm</TopMargin>
        <BottomMargin>2cm</BottomMargin>
        <ColumnSpacing>0.13cm</ColumnSpacing>
        <Style />
      </Page>
      <AutoRefresh>0</AutoRefresh>
      <ReportParameters>
        <ReportParameter Name="Time">
          <DataType>DateTime</DataType>
          <Prompt>ReportParameter1</Prompt>
        </ReportParameter>
      </ReportParameters>
      <rd:ReportUnitType>Cm</rd:ReportUnitType>
      <rd:ReportID>9a3949cd-13b4-4331-b18e-485314a1fd9e</rd:ReportID>
    </Report>
    As you see, the report shows the time with milliseconds set to 0.
    How do I pass the real milliseconds?

    Mikhail

    Monday, September 16, 2013 10:03 AM