Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
ReportViewer1.Visible = true;
            ReportViewer1.ProcessingMode = ProcessingMode.Local;
            
            var sqlConnection = new SQLConnectionStrings();
            var conReport = new SqlConnection(sqlConnection.strConn);
            var cmdReport = new SqlCommand();
            //var myDataAdapter = new SqlDataAdapter();
            //myDataAdapter.SelectCommand = cmdReport;
            
            SqlDataReader drReport;

            DataSet dsReport = new DataSet();
            //PerfLogDataSet();
            
            
            cmdReport.CommandType = CommandType.Text;
            cmdReport.Connection = conReport;
            conReport.Open();
            cmdReport.CommandText = baseQuery;
            drReport = cmdReport.ExecuteReader();
            conReport.Close();
           // myDataAdapter.Fill(dsReport);
            dsReport.Tables[0].Load(drReport);
            drReport.Close();
            conReport.Close();

            ReportViewer1.LocalReport.ReportPath = "Report.rdlc";
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dsReport.Tables[0]));

            string installTime;
            TimeSpan t = TimeSpan.FromMilliseconds(Convert.ToInt64(PerformanceLogController.deliveryTime.ToString()));

            installTime = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
                             t.Hours,
                             t.Minutes,
                             t.Seconds,
                             t.Milliseconds);
            
            string UinstallTime;
            TimeSpan tU = TimeSpan.FromMilliseconds(Convert.ToInt64(PerformanceLogController.deliveryTimeU.ToString()));

            UinstallTime = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
                             tU.Hours,
                             tU.Minutes,
                             tU.Seconds,
                             tU.Milliseconds);

            ReportParameter p1 = new ReportParameter("testParam", installTime.ToString());
            ReportParameter p2 = new ReportParameter("date", DateTime.Now.ToString());
            ReportParameter p3 = new ReportParameter("filterSum", filter);
            ReportParameter p4 = new ReportParameter("testParam1", UinstallTime.ToString());

            this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3, p4 });
            ReportViewer1.LocalReport.Refresh();
Posted
Updated 6-Aug-14 15:38pm
v2

C#
DataSet dsReport = new DataSet();
...
dsReport.Tables[0].Load(drReport);


The DataSet is empty. Try adding to it.

http://msdn.microsoft.com/en-us/library/system.data.dataset.tables(v=vs.110).aspx[^]
 
Share this answer
 
As already explained by PIEBALDconsult the problem is there is no Table[0] in the dataset thats why you are getting error. Change your data retrieval logic as follows.

C#
var sqlConnection = new SQLConnectionStrings();
DataSet dsReport = new DataSet();

using(var conReport = new SqlConnection(connString))
{
    conReport.Open();
    var cmdReport = new SqlCommand(baseQuery, conn);
    var myDataAdapter = new SqlDataAdapter(command);

    myDataAdapter.Fill(dsReport);
}


This will populate dsReport.Tables[0] that you can further use for reporting.
 
Share this answer
 
v2
Comments
Arvin Quizon 10-Aug-14 22:21pm    
Thank you sir. dsReport.Tables[0].Load(drReport); is unassigned. How would I fix this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900