Saqi

Saqi

  • NA
  • 63
  • 122.3k

How to dynamically pass Dataset to reportviewer ?

Sep 25 2012 1:40 PM
here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace Fabrication
{
    public partial class MaisVendido : Form
    {
        DB db = new DB();
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        public MaisVendido()
        {
            InitializeComponent();
            Getdataset();
            Getdatatable();
        }

        void Getdataset()
        {
            ds = db.ClientTable("select * from estoque");
        }
        void Getdatatable()
        {
            dt = db.Maisvendendo("select * from estoque");
        }
//this is myreportViewer page
        private void MaisVendido_Load( object sender, EventArgs e )
        {
            this.reportViewer1.Reset();
            this.reportViewer1.LocalReport.ReportPath = "Report3.rdlc";
            ReportDataSource rds = new ReportDataSource("Estoque", dt.TableName);
            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(rds);
            this.reportViewer1.LocalReport.Refresh();
        }

    }
}

 public DataTable Maisvendendo( String query )
        {
            DataTable dt=new DataTable();
            DataSet ds=new DataSet();
            MySqlConnection con = new MySqlConnection(MysqlConnect());
            con.Open();

            MySqlDataAdapter ad = new MySqlDataAdapter(query, con);
            ad.Fill(ds);
            dt.TableName = "Estoque";
            dt = ds.Tables[0];
            con.Close();
            return dt;
        }
       
i already added Report3.rdlc in my application and reportViewer1 now i dont know  how to pass dataset into report.

Answers (2)