gpt4 book ai didi

c# - 找不到表 0 错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:18:43 29 4
gpt4 key购买 nike

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

Exception Details: System.IndexOutOfRangeException: Cannot find table 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();

最佳答案

dsReport 中没有表格。 dsReport 不为空,否则您将遇到对象引用异常。

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

mydataAdapter.Fill(dsReport);

更多关于 SQLDataAdapter.Fill

关于c# - 找不到表 0 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25112377/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com