Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,

How can I pass dataset to report viewer in visual studio. Note I already create the dataset I just need to pass it?
Posted

Create New Report Wizard, When you are adding new Report Wizard. One window will come. On that window you can select your dataset. Now you got your data set to Reprt Viewer(.rdlc) page. Through Website data source you can drag each field to your .rdlc page.
 
Share this answer
 
Comments
Member 8584763 14-Apr-13 8:47am    
All I get so far is this.

string sql = "SELECT * FROM product where dat>='" + yy + "' and dat<'" + xx + "'and product_sold>0 and total >0";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, con);
DataSet5 ds = new DataSet5();
dscmd.Fill(ds, "product");
int l = 0;
string ll = Convert.ToString(l);
if (ds.Tables["product"].Rows.Count.ToString() == ll.ToString())
{
MessageBox.Show("لا يوجد تقارير ");
}
else

MessageBox.Show(ds.Tables["product"].Rows.Count.ToString());
Now, I want to pass to report viewer
 
Share this answer
 
Comments
Member 8584763 14-Apr-13 8:47am    
All I get so far is this.

string sql = "SELECT * FROM product where dat>='" + yy + "' and dat<'" + xx + "'and product_sold>0 and total >0";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, con);
DataSet5 ds = new DataSet5();
dscmd.Fill(ds, "product");
int l = 0;
string ll = Convert.ToString(l);
if (ds.Tables["product"].Rows.Count.ToString() == ll.ToString())
{
MessageBox.Show("لا يوجد تقارير ");
}
else

MessageBox.Show(ds.Tables["product"].Rows.Count.ToString());
Now, I want to pass to report viewer
Dears,
should I design the report rdlc 1st?
or it will be created automatically the data table once i make the procedure ?
 
Share this answer
 
private void btnSearch_Click(object sender, EventArgs e)
       {
           DataSet Ds = new DataSet();
           CheckConnection Obj = new CheckConnection();

           Ds = Obj.checkDBConnection(txtSearch.Text.ToString());
           if (Ds.Tables.Count > 0)
           {
               if (Ds.Tables[0].Rows.Count > 0)
               {
                   if (chkAddress.Checked == true)
                   {
                       CrystalReport1 rpt = new CrystalReport1();
                       rpt.Database.Tables[0].SetDataSource(Ds.Tables[0]);
                       this.crystalReportViewer1.ReportSource = rpt;
                   }
                   else
                   {
                       CrystalReport2 rpt = new CrystalReport2();
                       rpt.Database.Tables[0].SetDataSource(Ds.Tables[0]);
                       this.crystalReportViewer1.ReportSource = rpt;
                   }

               }
           }
       }
 
Share this answer
 
C#
protected void Page_Load(object sender, EventArgs e)
    {
        conn = new OdbcConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
        conn.Open();

        if (!Page.IsPostBack)
        {
            runRptViewer();
        }
    }
<pre></pre>
    private void rptGetDataset()
    {
        DataSet ds = new DataSet();
        ds.DataSetName = "dsNewDataSet";
        string sql = "";
        sql = "SELECT ID, CLIENT_ID, AGENT_ID FROM TBLMAILDELETED";
        OdbcDataAdapter da = new OdbcDataAdapter(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 ID, CLIENT_ID, AGENT_ID FROM TBLMAILDELETED";
        OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);
        da.Fill(dss);
        DataTable dt = dss.Tables[0];
        return dt;
    }

    private void runRptViewer()
    {
        this.ReportViewer1.Reset();
        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.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();
    }
 
Share this answer
 
Comments
Member 8584763 16-Apr-13 10:41am    
There're copule of errors:

Error 2 'Microsoft.Reporting.WinForms.ReportViewer' does not contain a definition for 'DataBind' and no extension method 'DataBind' accepting a first argument of type 'Microsoft.Reporting.WinForms.ReportViewer' could be found (are you missing a using directive or an assembly reference?)

Error 1 The name 'Server' does not exist in the current context
Member 10458979 13-Dec-13 2:46am    
Hi,
I'm using windows application and i have run this code but there is no result.i have a confusion about the value of _path which is described above, is path of the project or other? Please help me.
[no name] 16-Apr-13 12:23pm    
i given its is for ASP.Net
if you are using windows application please change to
this.ReportViewer1.LocalReport.ReportPath ="Report.rdlc";

remove this line
this.ReportViewer1.DataBind();
Member 8584763 16-Apr-13 12:57pm    
I did like you said but there are no result s
[no name] 16-Apr-13 13:17pm    
can youpleasse look into this

http://www.mindstick.com/Articles/13169999-ef3b-496c-b502-caef973c3bb2/?Using%20ReportViewer%20in%20WinForms%20C

this is working fine in my system

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900