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#

  • 2011年8月30日 下午 06: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


    • 已編輯 Pradeep18 2011年9月6日 下午 05:01
    •  

所有回覆

  • 2012年2月5日 下午 09:48
     
     已答覆

    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();

    • 已標示為解答 Pradeep18 2012年3月9日 下午 04:24
    •  
  • 2012年3月9日 下午 04:25
     
     
    thanks Giannatee it worked :)