none
Report viewer with rdl file in local mode RRS feed

  • Question

  •  

    Hi All,

     

    I have .rdl file of the report I want to use rdl file for report viewer and I can set data source manually..

     

    My report set correctly.

    i set datasource also.

    but I cant see report.

    But datasource has the data. I checked it.

    I think I am missing something in this.. Please help me..

     

    My Code is as below.

    private void btnReport_Click(object sender, EventArgs e)

    {

    RptViewer.LocalReport.ReportPath = @"C:\MY WORK\Reporting Service\Rporting Service\sales.rdl"

    RptViewer.LocalReport.DataSources.Add( new Microsoft.Reporting.WinForms.ReportDataSource("sales",GetSalesData()));

    SetReportParameter("");

    RptViewer.Visible = true;

    }

     

     

    private DataTable GetSalesData()

    {

    SqlCommand cmd = new SqlCommand("GetSales", new SqlConnection("Data Source=ABC;Initial Catalog=MYDatabase;Integrated Security=SSPI;Persist Security Info=False;"));

    cmd.CommandType = CommandType.StoredProcedure;

    cmd.CommandTimeout = 1000;

    // SqlParameter[] param = new SqlParameter[3];

    cmd.Parameters.AddWithValue("@pCenterId", "9B95363B-F82D-4E55-AD89-2AD928AC981F");

    cmd.Parameters.AddWithValue("@pEmployeeId", DBNull.Value);

    cmd.Parameters.AddWithValue("@pclientId", DBNull.Value);

    cmd.Parameters.AddWithValue("@pStartDate ", "06/04/2007");

    cmd.Parameters.AddWithValue("@pEndDate ", "06/09/2007");

    SqlDataAdapter da = new SqlDataAdapter(cmd);

    DataTable dt = new DataTable();

    da.Fill(dt);

    return dt;

    }

     

    private void SetReportParameter(string ReportTitle)

    {

    Microsoft.Reporting.WinForms.ReportParameterInfoCollection ParInfo;

    Microsoft.Reporting.WinForms.ReportParameter[] RepParameter;

    ParInfo = RptViewer.LocalReport.GetParameters();

    RepParameter = new Microsoft.Reporting.WinForms.ReportParameter[ParInfo.Count];

    for (int j = 0; j < ParInfo.Count; j++)

    {

    switch (ParInfo[j].Name.ToLower())

    {

    case "centername" :

    RepParameter[j] = new Microsoft.Reporting.WinForms.ReportParameter("CenterName", "Bensalem", false);

    break;

    case "centernum" :

    RepParameter[j] = new Microsoft.Reporting.WinForms.ReportParameter("CenterNum", "12345", false

    break;

    case "pcenterid":

    RepParameter[j] = new Microsoft.Reporting.WinForms.ReportParameter("pCenterID", "9B95363B-F82D-4E55-AD89-2AD928AC981F",false);

    break;

    case "pemployeeid":

    RepParameter[j] = new Microsoft.Reporting.WinForms.ReportParameter("pEmployeeid",DBNull.Value.ToString());

    break;

    case "pclientid":

    RepParameter[j] = new Microsoft.Reporting.WinForms.ReportParameter("pClientId",DBNull.Value.ToString());

    break;

    case "pstartdate":

    RepParameter[j] = new Microsoft.Reporting.WinForms.ReportParameter("pStartDate","06/04/2007") ;

    break;

    case "penddate":

    RepParameter[j] = new Microsoft.Reporting.WinForms.ReportParameter("pEndDate","06/09/2007

    break;

    }

    }

    RptViewer.LocalReport.SetParameters(RepParameter);

     

    }

     

     

    Thanks.

    Monday, August 13, 2007 2:09 PM

Answers

  • All I was missing was

     

     

    RptViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;

    RptViewer.RefreshReport();

     

     

    And now it works.

    Monday, August 13, 2007 3:48 PM

All replies

  •  

    I can export the report in Excel perfectly fine.. I dont know why its not showing in reportviewer.

     

     

    My code for exporting in excel is as follows:

     

    string mimetype;

    string encoding;

    string ext;

    string[] streamids = new string[5];

    Microsoft.Reporting.WinForms.Warning[] warnings = new Microsoft.Reporting.WinForms.Warning[5];

    try{

    byte[] bytes = RptViewer.LocalReport.Render("Excel", "<DeviceInfo> <SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>", out mimetype, out encoding,out ext, out streamids, out warnings);

    using (FileStream fs = new FileStream(@"c:\Monthly Sales.xls", FileMode.Create))

    {

    fs.Write(bytes, 0, bytes.Length);

    fs.Close();

    }

    Monday, August 13, 2007 3:27 PM
  • All I was missing was

     

     

    RptViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;

    RptViewer.RefreshReport();

     

     

    And now it works.

    Monday, August 13, 2007 3:48 PM