找不到表0错误

时间:2014-08-04 05:42:35

标签: c# asp.net

找不到表0。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

  

异常详细信息:System.IndexOutOfRangeException:找不到表   0

代码的错误部分是“dsReport.Tables[0].Load(drReport);

我的generateReport代码是:

ReportViewer1.Visible = true;
ReportViewer1.ProcessingMode = ProcessingMode.Local;

var sqlConnection = new SQLConnectionStrings();
var conReport = new SqlConnection(sqlConnection.strConn);
var cmdReport = new SqlCommand();


SqlDataReader drReport;

DataSet dsReport = new DataSet();
//PerfLogDataSet();
conReport.Open();

cmdReport.CommandType = CommandType.Text;
cmdReport.Connection = conReport;
cmdReport.CommandText = baseQuery;
drReport = cmdReport.ExecuteReader();
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();

1 个答案:

答案 0 :(得分:1)

dsReport中没有表格。 dsReport不为null,否则您将获得对象引用异常。

您应该创建一个SQLDataAdapter并像这样填充DataTable

mydataAdapter.Fill(dsReport);

更多关于SQLDataAdapter.Fill