[英]How to Create From ReportViewer in C# by using coded DataSet
我想在C#ReportViewer上以某種方式創建類似發票的發票。 但我不知道如何通過代碼格式化報告。 我的代碼出錯了。 這是我使用的:
private void Form1_Load(object sender, EventArgs e)
{
try
{
conn = new SqlConnection();
conn.ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=PrototypeV9;Integrated Security=True";
conn.Open();
if (conn.State == ConnectionState.Open)
{
MessageBox.Show("HEY");
}
this.reportViewer1.Reset();
this.reportViewer1.LocalReport.ReportPath = @"C:\Users\Lenon\Documents\Euge's Folder\SampReport\SampReport\bin\Report2.rdlc";
ReportDataSource rds = new ReportDataSource("dsNewDataSet_Table", getData());
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(rds);
//this.reportViewer1.DataBind();
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
}
catch (Exception ex) {
MessageBox.Show("no");
}
}
private void rptGetDataset()
{
string path = @"C:\Program Files";
DataSet ds = new DataSet();
ds.DataSetName = "dsNewDataSet";
string sql = "";
sql = "select * from Sample3 where ProductID = 'ITM42512'";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
ds.GetXmlSchema();
da.Fill(ds);
ds.WriteXmlSchema(path + @"\App_Code\Ds.xsd");
ds.WriteXml(path + @"\App_Code\Ds.xml");
}
private DataTable getData()
{
DataSet dss = new DataSet();
string sql = "";
sql = "select * from Sample3 where ProductID = 'ITM42512'";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(dss);
DataTable dt = dss.Tables[0];
return dt;
}
我怎樣才能解決我的問題? 或者是否有其他方法可以使用ReportViewer創建發票。 謝謝!
這是一個古老的問題,你可能已經有了答案,但我一直在研究類似的東西,並且經歷了似乎是同樣的情況(這就是我在這里的原因)。
由於缺少RDLC文件,因此觸發了該錯誤。 您可以靜態或動態地創建RDLC定義。
對於靜態版本,您可以使用Visual Studio的向導輕松找到有關如何執行此操作的許多教程。 如果您想動態地執行此操作,那么這個答案將導致為.Net 2.0中的SSRS 2005設計的代碼項目教程。 它非常好而且詳細。
在reportviewer中有一個不同的解決方案(我使用的是這個) ? ,尋找“動態生成RDLC - 表”。 示例代碼將幫助您創建自己的版本; 它不需要很多更改就可以讓它在您的項目中運行。
如果您處理大量報告,動態版本特別有用。
希望這會有所幫助,歡呼!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.