我在我的reportviewer上得到一個錯誤,我不知道如何解決此問題.... 我得到的錯誤是:「尚未爲數據源「請求」提供數據源實例。「 我試過尋找這個,但找不到任何我能看到的是錯誤的,有人可以請我指出正確的方向嗎?這是我的reportvierer看起來像:數據源實例尚未提供給數據源'請求'
<rsweb:ReportViewer ID="rptViewer" runat="server" Height="654px"
Width="924px" Font-Names="Verdana" Font-Size="8pt"
InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana"
WaitMessageFont-Size="14pt">
<LocalReport ReportPath="Report.rdlc">
</LocalReport>
這是我使用中的ReportViewer代碼:
SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
if (!Page.IsPostBack)
{
runRptViewer();
}
}
private DataTable getData()
{
DataSet dss = new DataSet();
string sql = "";
sql = "SELECT CC_Request.Company, CC_Request.Attention, CC_Request.Telephone, CC_Request.Email, CC_Items.Model, CC_Items.SerialNo, CC_ItemsRequested.Item, CC_ItemsRequested.Quantity, CC_ItemsRequested.Price, CC_ItemsRequested.ModelID, CC_Items.RequestID FROM CC_Request INNER JOIN CC_Items ON CC_Request.RequestID = CC_Items.RequestID INNER JOIN CC_ItemsRequested ON CC_Items.ModelID = CC_ItemsRequested.ModelID WHERE (CC_Request.Company = 'Alpha') AND (CC_ItemsRequested.ModelID = 20) AND (CC_Items.RequestID = 1)";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(dss);
DataTable dt = dss.Tables[0];
return dt;
}
private void runRptViewer()
{
this.rptViewer.Reset();
this.rptViewer.LocalReport.ReportPath = Server.MapPath("Reports\\Report.rdlc");
ReportDataSource rds = new ReportDataSource("dsNewDataSet_Table", getData());
this.rptViewer.LocalReport.DataSources.Clear();
this.rptViewer.LocalReport.DataSources.Add(rds);
this.rptViewer.DataBind();
this.rptViewer.LocalReport.Refresh();
}
任何幫助將不勝感激。
編輯-----------------------
這不起作用或者:
private DataTable getData()
{
DataTable dtable = new DataTable();
dtable.TableName = "dtNewDataSet_Table";
string sql = "";
sql = "SELECT CC_Request.Company, CC_Request.Attention, CC_Request.Telephone, CC_Request.Email, CC_Items.Model, CC_Items.SerialNo, CC_ItemsRequested.Item, CC_ItemsRequested.Quantity, CC_ItemsRequested.Price, CC_ItemsRequested.ModelID, CC_Items.RequestID FROM CC_Request INNER JOIN CC_Items ON CC_Request.RequestID = CC_Items.RequestID INNER JOIN CC_ItemsRequested ON CC_Items.ModelID = CC_ItemsRequested.ModelID WHERE (CC_Request.Company = 'Alpha') AND (CC_ItemsRequested.ModelID = 20) AND (CC_Items.RequestID = 1)";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(dtable);
DataTable dt = dtable;
return dt;
}
側面說明:爲什麼你創建和填充一個'DataSet'時,你只返回它的第一個表呢?創建一個'DataTable'並填充它。 –
@Tim Schmelter,即不工作..... – Kerieks