我想在 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 创建发票。谢谢!