none
use a created DataSet in reportViewer RRS feed

  • Question

  • Hi?!
    I created a dataSet by code, and I want to use at reportViewer, ho wcan I do?

    Mello.
    Monday, April 7, 2008 3:09 PM

All replies

  • Hello

    First you need to create ReportDataSource objects. Next you need to set proper values of this objects and at the end add it to LocalReport and set LocalReport's file path. For example:

     

    Code Snippet

    SqlConnection conn = new SqlConnection(@"Data Source=sql2000srv;Initial Catalog=testDB;Integrated Security=True");

    SqlCommand cmd = new SqlCommand("SELECT col1, col2, col3 FROM temp_tbl");

    conn.Open();

    cmd.Connection = conn;

    DataTable dt = new DataTable();

    DataSet ds = new DataSet();

    dt.Load(cmd.ExecuteReader());

    ds.Tables.Add(dt);

    ReportDataSource rds = new ReportDataSource("rds00");

    rds.Name = "some_name";

    rds.Value = ds;

    reportViewer1.LocalReport.DataSources.Add(rds);

    reportViewer1.LocalReport.ReportPath = "Report1.rdlc";

    reportViewer1.RefreshReport();

     

    Hope this helps.

    Tuesday, April 8, 2008 12:11 PM
  • Hi

    I tried your code but it didnt work

    error = Value does not fall within the expected range

    on the line  rds.value = ds

     

    Any ideas?

    Thanks

    Paul

     

    Saturday, April 12, 2008 2:20 PM
  • Ouch, sorry...my mistake, for datasets you must use bindingsource - code should be like this:

     

    Code Snippet

    SqlConnection conn = new SqlConnection(@"Data Source=sql2000srv;Initial Catalog=testDB;Integrated Security=True");

    SqlCommand cmd = new SqlCommand("SELECT col1, col2, col3 FROM temp_tbl");

    conn.Open();

    cmd.Connection = conn;

    DataTable dt = new DataTable();

    DataSet ds = new DataSet();

    dt.Load(cmd.ExecuteReader());

    dt.TableName = "some_name01";

    ds.Tables.Add(dt);

     

    Container ctr = new System.ComponentModel.Container();

    BindingSource bs1 = new BindingSource(ctr);

    bs1.DataMember = "some_name01";

    bs1.DataSource = ds;

     

    ReportDataSource rds = new ReportDataSource("rds00");

    rds.Value = bs1;

     

    reportViewer1.LocalReport.DataSources.Add(rds);

    reportViewer1.LocalReport.ReportPath = "Report1.rdlc";

    reportViewer1.RefreshReport();

     

    Monday, April 14, 2008 10:07 AM
  • try this


    SqlConnection conn = new SqlConnection(@"Data Source=sql2000srv;Initial Catalog=testDB;Integrated Security=True");

    SqlCommand cmd = new SqlCommand("SELECT col1, col2, col3 FROM temp_tbl");

    conn.Open();

    cmd.Connection = conn;

    DataTable dt = new DataTable();

    DataSet ds = new DataSet();

    dt.Load(cmd.ExecuteReader());

    ds.Tables.Add(dt);

    reportSource = new ReportDataSource("eWorderDS_eworder", eworderAllDS_H.tables[0]);

    reportViewer1.LocalReport.DataSources.Add(reportSource );

    reportViewer1.LocalReport.ReportPath = "Report1.rdlc";

    reportViewer1.RefreshReport();

    Tuesday, April 15, 2008 10:29 AM