I have a report viewer and a dataset with 4 tables, i would

Mar 8 2015 5:20 AM
 
here is my code:

using

 

 

System;


using

 

 

System.Collections.Generic;


using

 

 

System.ComponentModel;


using

 

 

System.Data;


using

 

 

System.Drawing;


using

 

 

System.Data.SqlClient;


using

 

 

System.Text;


using

 

 

System.Threading.Tasks;


using

 

 

System.Windows.Forms;


using

 

 

Microsoft.Reporting.WinForms;



namespace

 

 

NewTechBookStore


{


   

 

public partial class Form1 : Form


    {


       

 

public Form1()


        {


            InitializeComponent();


        }


  


    



public

 

 

string report;



DataTable

 

 

dtBook;


DataTable

 

 

dtCustomer;


DataTable

 

 

dtBillDetails;


DataTable

 

 

dtPayment;


DataTable

 

 

dtAddress;



       

 

private void Form1_Load(object sender, EventArgs e)



       {


          

 

SqlConnection con = new SqlConnection();


          

 

string cs = "Data Source=.; Initial Catalog=NewTechBookStore;User id=sa;Password=123456";


           con.ConnectionString = cs;


          

 

SqlDataAdapter da = new SqlDataAdapter("testSP", con);


           da.SelectCommand.CommandType =

 

CommandType.StoredProcedure;


          

 

DataSet  ds = new DataSet("New");


           da.Fill(ds);


           dtAddress = ds.Tables[0];


           dtBillDetails = ds.Tables[1];


           dtBook = ds.Tables[2];


           dtCustomer = ds.Tables[3];


           dtPayment = ds.Tables[4];


          

 

for (int i = 0; i < ds.Tables.Count; i++)


           {


               comboBox1.Items.Add(ds.Tables[i].TableName);


           }               


           


          

 

ReportDataSource reportDataSource = new ReportDataSource();


          

 

const string rut = "Reporting.Reports.";


           


          

 

if (textBox1.Text.Trim() == report)        


          


          

 

this.reportViewer1.ProcessingMode = ProcessingMode.Local;


          

 

this.reportViewer1.LocalReport.ReportEmbeddedResource = rut + report + ".rdlc";


          

 

this.reportViewer1.LocalReport.DataSources.Clear();      


           reportDataSource.Value = ds.Tables[2];


          

 

this.reportViewer1.LocalReport.DataSources.Add(reportDataSource);


        


          

 

this.reportViewer1.RefreshReport();


        }


    }


}


Answers (1)