How to dynamically use dataset to genrate report?

Jan 17 2014 4:20 PM

Hi , I want to generate a report using reportviewer, I have tried every way to generate using dynamically to retrieving dataset and transferring it into datatable and also ilist, but nothing helped me.Still the reportviewer is giving a blank page with only the header portion visible.Can you help me resolve if anything is missing in this piece of code. This is the page containing the reportviewer.

 

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting;
using System.Data.SqlClient;
using Microsoft.Reporting.WinForms;

namespace testcrystal
{
public class temp
{
public string fnm,lnm;
public int sal;
public temp(string fn,string ln,int sl)
{
fnm = fn;
lnm = ln;
sal = sl;
}
}
public partial class Form1 : Form
{
SqlConnection cn;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'tryDataSet2.emptmp' table. You can move, or remove it, as needed.
//this.emptmpTableAdapter.Fill(this.tryDataSet2.emptmp);
DataTable dt = new DataTable();
cn=new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Administrator\Documents\Visual Studio 2010\Projects\testcrystal\testcrystal\try.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
cn.Open();
cmd=new SqlCommand("select * from emp where sal>35000",cn);
cmd.CommandType = CommandType.Text;
da=new SqlDataAdapter(cmd);
ds=new DataSet();
da.Fill(ds);
dt = ds.Tables[0];
IList<temp> emptemp = new List<temp>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
emptemp.Add(new temp(ds.Tables[0].Rows[i].ItemArray[0].ToString(), ds.Tables[0].Rows[i].ItemArray[1].ToString(), Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[2].ToString())));
}
//string reportPath = Path.Combine("Report1.rdlc");
this.reportViewer1.LocalReport.ReportPath = @"C:\Users\Administrator\Documents\Visual Studio 2010\Projects\testcrystal\testcrystal\Report1.rdlc";

ReportDataSource rds = new ReportDataSource("Dataset1", emptemp);
this.reportViewer1.LocalReport.DataSources.Add(rds);

this.emptmpTableAdapter.Fill(this.tryDataSet2.emptmp);
this.reportViewer1.RefreshReport();

//this.reportViewer1.RefreshReport();
//MessageBox.Show(dt.Rows.Count.ToString());
//cn.Close();

// TODO: This line of code loads data into the 'tryDataSet.emp' table. You can move, or remove it, as needed.



}
}
}

Thanks Everyone


Answers (1)