C# DataTable作为ReportViewer中的数据源
(首先,我对我的英语很抱歉,因为我是个陌生人,我不太懂英语) 我在一个学校项目中工作。但我需要在ReportViewer中将DataTable设置为数据源。首先,用户键入文档的ID,然后单击按钮,该按钮调用一个类,该类在我的数据库中进行选择并返回12个字段。我已经创建了一个数据集,其中包含选择结果的所有字段,并且我已经选择它作为报告数据源。但我需要将select的数据传输到数据集,因为当我启动应用程序时,报告有一个错误。这是代码,希望你能帮我!谢谢 巴特顿代码:C# DataTable作为ReportViewer中的数据源,c#,winforms,datatable,datasource,reportviewer,C#,Winforms,Datatable,Datasource,Reportviewer,(首先,我对我的英语很抱歉,因为我是个陌生人,我不太懂英语) 我在一个学校项目中工作。但我需要在ReportViewer中将DataTable设置为数据源。首先,用户键入文档的ID,然后单击按钮,该按钮调用一个类,该类在我的数据库中进行选择并返回12个字段。我已经创建了一个数据集,其中包含选择结果的所有字段,并且我已经选择它作为报告数据源。但我需要将select的数据传输到数据集,因为当我启动应用程序时,报告有一个错误。这是代码,希望你能帮我!谢谢 巴特顿代码: SelectDocumento
SelectDocumento doc = new SelectDocumento();
doc.ImprimirDoc(int.Parse(txtID.Text));
选择我的数据库中的数据的类:
public void ImprimirDoc(int id)
{
string pesquisar = "CALL SP_Imprimir_Documento(" + id + ")";
MySqlConnection con;
con = new MySqlConnection("Persist Security Info=false; server=localhost; database=hospital; uid=root; pwd=");
MySqlDataAdapter adapter = new MySqlDataAdapter(pesquisar, con);
DataTable dt = new DataTable();
dt.TableName = "DataSet1";
con.Open();
adapter.Fill(dt);
ImprimirDocumento imprimir = new ImprimirDocumento(dt);
imprimir.ShowDialog();
}
报告表格的代码:
private DataTable proc;
public ImprimirDocumento(DataTable select)
{
InitializeComponent();
proc = select;
}
ConexaoHospital bd = new ConexaoHospital();
SelectDocumento doc = new SelectDocumento();
private void ImprimirDocumento_Load(object sender, EventArgs e)
{
this.rptDocumento.RefreshReport();
this.rptDocumento.LocalReport.DataSources.Clear();
Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", proc);
this.rptDocumento.LocalReport.DataSources.Add(rprtDTSource);
this.rptDocumento.RefreshReport();
}
报告显示的错误:
如果有人有类似的问题,我的文章的这种方式是正确的,我的问题是因为我的ReportViewer数据集名称与我的DataTable不同。我的数据表名为“DataSet1”,数据集名为“Documento”。我更改了“DataSet1”的数据集名称,它可以正常工作。从报表查看器复制错误消息,并使用或进行翻译,然后将英文错误消息放在此处,而不是错误的屏幕截图。这样你可能会得到更多的帮助。如果我还没有找到解决问题的方法,我会这么做。多谢各位!