a data source instance has not been supplied for the data source 'dataset1' in c#

Answered a data source instance has not been supplied for the data source 'dataset1' in c#

  • 30. srpna 2011 18:40
     
     

    Hello i am doing a project in DotNet 2010. I have a problem in my code because of this. I want to create a report using a mdf file.

    query="select * from ledger where nm="+textbox1.text;

    SqlCommand cmd4=new SqlCommand(query,cn1);

    DataTable dt1 = new DataTable();
                Adapter = new SqlDataAdapter(cmd4);
                Adapter.Fill(dt1);
                Adapter.Fill(ds1);
                //cn1.Close();
               
               
                this.reportViewer1.Reset();
                this.reportViewer1.LocalReport.DataSources.Clear();
                this.reportViewer1.LocalReport.ReportPath=@"C:\Users\PRADEEP\Documents\Visual Studio 2010\Projects\WindowsFormsApplication10\WindowsFormsApplication10\Report3.rdlc";
                ReportDataSource rds = new ReportDataSource("ds1_ledger",dt1 );
               
                this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ledger",dt1));
                this.reportViewer1.ZoomMode = ZoomMode.Percent;
                this.reportViewer1.RefreshReport();

     

    But when i enter the value in text box and click i am getting the following error

    a data source instance has not been supplied for the data source 'dataset1'

     

    i have designed my rdlc using dataset2.

    mail me to pradeep18.kul@gmail.com


    • Upravený Pradeep18 6. září 2011 17:01
    •  

Všechny reakce

  • 5. února 2012 21:48
     
     Odpovědět

    replace the snippet on the 3rd to the last line, to rds.

     

    query="select * from ledger where nm="+textbox1.text;

    SqlCommand cmd4=new SqlCommand(query,cn1);

    DataTable dt1 = new DataTable();
                Adapter = new SqlDataAdapter(cmd4);
                Adapter.Fill(dt1);
                Adapter.Fill(ds1);
                //cn1.Close();
                
                
                this.reportViewer1.Reset();
                this.reportViewer1.LocalReport.DataSources.Clear();
                this.reportViewer1.LocalReport.ReportPath=@"C:\Users\PRADEEP\Documents\Visual Studio 2010\Projects\WindowsFormsApplication10\WindowsFormsApplication10\Report3.rdlc";
                ReportDataSource rds = new ReportDataSource("ds1_ledger",dt1 );
                
                this.reportViewer1.LocalReport.DataSources.Add(rds);
                this.reportViewer1.ZoomMode = ZoomMode.Percent;
                this.reportViewer1.RefreshReport();

    • Označen jako odpověď Pradeep18 9. března 2012 16:24
    •  
  • 9. března 2012 16:25
     
     
    thanks Giannatee it worked :)