想法是输入新字段,然后在报告中显示它们 http://www.mediafire.com/view/6sla63hpecx2cc9/workflow.PNG mediafire.com/view/1juiekfr5gbk48d/theproplem.GIF
我在 DataSet 中过滤表格并假设显示数据,它与 DataGridView 完美配合,现在我希望找到一种方法来用填充 datagrid 的相同数据集填充报表
public partial class bill : Form
{
SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=G:\I.S\C#\C#(Projects)\Nothin\billingSystem\billingSystem\Store.mdf;Integrated Security=True;User Instance=True");
public bill(string Cusn,string su,string am,string to,string Di, string Cnum)
{
InitializeComponent();
label1.Text = Cusn;
label2.Text = su;
label3.Text = am;
label4.Text = to;
label5.Text = Di;
label6.Text = DateTime.Now.ToString("d/M/yyyy");
label7.Text = Cnum;
}
private void bill_Load(object sender, EventArgs e)
{
LoadReport();
}
private void LoadReport()
{
int R = Convert.ToInt32(label7.Text);
SqlDataAdapter ADAP = new SqlDataAdapter("Select * from Newbill where Con = '" + R + "'", cn);
DataSet DS = new DataSet();
ADAP.Fill(DS, "Store");
dataGridView1.DataSource = DS.Tables["Store"];
// TODO: This line of code loads data into the 'DataSet10.NewBill' table. You can move, or remove it, as needed.
this.NewBillTableAdapter.Fill(this.DataSet10.NewBill, R);
this.reportViewer1.RefreshReport();
ReportParameter[] allPar = new ReportParameter[5]; // create parameters array
ReportParameter parSu = new ReportParameter("Summation", label2.Text);
ReportParameter parDiscount = new ReportParameter("Discount", label5.Text);
ReportParameter parDisA = new ReportParameter("DiscountAmount", label3.Text);
ReportParameter parTotal = new ReportParameter("Total", label4.Text);
ReportParameter parCus = new ReportParameter("CustomerName", label1.Text);
allPar[0] = parSu; //assign parameters to parameter array
allPar[1] = parDiscount;
allPar[2] = parTotal;
allPar[3] = parDisA;
allPar[4] = parCus;
this.reportViewer1.LocalReport.SetParameters(allPar);
this.reportViewer1.RefreshReport();
// TODO: This line of code loads data into the 'DataSet1.NewBill' table. You can move, or remove it, as needed.
//this.NewBillTableAdapter.Fill(this.DataSet1.NewBill, R, O);
//this.reportViewer1.RefreshReport();
}
}
我看过这个:http ://www.verious.com/qa/how-can-i-load-datatable-as-report-data-source/
实际上我需要一些步骤来使用查询从数据库中查看数据以过滤报告中的数据,我在谷歌上找到的所有内容都是这样的:http: //www.codeproject.com/Articles/31862/Dynamic-Binding-Of- RDLC-To-ReportViewer但在插入新字段时它不起作用。
怎么样,我尝试刷新数据集以包含表中发生的更改(在我的情况下插入新行“新数据”)但它给了我:
A data source instance has not been supplied for the data source 'DataSet 10_NewBill'.
private void LoadReport()
{
int R = Convert.ToInt32(label7.Text);
this.reportViewer1.LocalReport.DataSources.Clear();
DataTable dt = new DataTable();
dt = this.NewBillTableAdapter.GetData(R);
ReportDataSource rprtDTSource = new ReportDataSource(dt.TableName, dt);
this.reportViewer1.LocalReport.DataSources.Add(rprtDTSource);
this.reportViewer1.RefreshReport();
// TODO: This line of code loads data into the 'DataSet10.NewBill' table. You can move, or remove it, as needed.
this.NewBillTableAdapter.Fill(this.DataSet10.NewBill,R );
this.reportViewer1.RefreshReport();
ReportParameter[] allPar = new ReportParameter[5]; // create parameters array
ReportParameter parSu = new ReportParameter("Summation", label2.Text);
ReportParameter parDiscount = new ReportParameter("Discount", label5.Text);
ReportParameter parDisA = new ReportParameter("DiscountAmount", label3.Text);
ReportParameter parTotal = new ReportParameter("Total", label4.Text);
ReportParameter parCus = new ReportParameter("CustomerName", label1.Text);
allPar[0] = parSu; //assign parameters to parameter array
allPar[1] = parDiscount;
allPar[2] = parTotal;
allPar[3] = parDisA;
allPar[4] = parCus;
this.reportViewer1.LocalReport.SetParameters(allPar);
this.reportViewer1.RefreshReport();
}
和这个
int R = Convert.ToInt32(label7.Text);
SqlDataAdapter ADAP = new SqlDataAdapter("Select * from Newbill where Con = '" + R + "'", cn);
DataSet DS = new DataSet();
ADAP.Fill(DS, "Store");
DataTable dt = new DataTable();
dt.TableName = "Store";
cn.Open();
ADAP.Fill(dt);
reportViewer1.ProcessingMode = ProcessingMode.Local;
ReportDataSource source = new ReportDataSource("Store", dt);
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(source);
reportViewer1.DataBind();
reportViewer1.LocalReport.Refresh();
cn.Close();
它给了我:错误'Microsoft.Reporting.WinForms.ReportViewer'不包含'DataBind'的定义并且没有扩展方法'DataBind'接受'Microsoft.Reporting.WinForms.ReportViewer'类型的第一个参数可以找到
那么我在使用时需要什么参考?