0
votes

(First of all I'm so sorry about my english, because I'm a stranger and I don't know well)

I'm working in a school project. But I need to set a DataTable as DataSource in ReportViewer. First the user type the ID of the Document, and click on the button, the button calls an class that do a select in my database and return 12 fields. I've created a DataSet with all fields that the select results and I've selected it as the Report DataSource. But I need to transfer the data of the select to the DataSet, because when I start my application the Report has an error. Here is the code, and I hope you can help me! Thanks.

Buttton Code:

SelectDocumento doc = new SelectDocumento();
        doc.ImprimirDoc(int.Parse(txtID.Text));

Class that select data in my database:

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();
    }

Code of the Report Form:

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();
    }

Error that the Report Displays:

Error

1
Copy the error message from your report viewer and translate it using google translate or bing translator and put the English error message here instead of an screenshot of the error. This way you may receive more help. - Reza Aghaei
I'll do it if I haven't founded the solution for my problem. Thank you a lot! - lucasgsf

1 Answers

0
votes

If someone have a simmilar problem this way of my post is correct and my problem was because my ReportViewer DataSet name was different than my DataTable. My DataTable name was "DataSet1" and my DataSet name was "Documento". I changed the DataSet name for "DataSet1" and it works.