0

i have a dataset with 2 datatable aand I need to use 2 sql request to display data in crystal report. So i create 2 datatable in my dataset (DataTable1 and dataTable2) I tried this code but it always execute the second sql request!!

 con.ConnectionString = @"connection";

            string sql = "MyRequest1";
            string sql1 = "MyRequest2";

            DataSet1 ds = new DataSet1();  

            SqlDataAdapter dad = new SqlDataAdapter(sql, con);
            SqlDataAdapter dad1 = new SqlDataAdapter(sql1, con);

            dad.Fill(ds.Tables["DataTable1"]);
            dad1.Fill(ds.Tables["DataTable2"]);

            CrystalReport1 report = new CrystalReport1();

            report.SetDataSource(ds.Tables["DataTable2"]);
            report.SetDataSource(ds.Tables["DataTable1"]);

            crystalReportViewer1.ReportSource = report;

            crystalReportViewer1.Refresh();
leila.net
  • 81
  • 3
  • 18
  • Have u checked whether data is getting fetched by the first sql, if not run in debug mode & check the ds.Tables["DataTable1"]. Also u can check the sql in ur db – Shubhojit Apr 22 '15 at 10:59
  • i have maked some modification to the code. now it execute only the first request and display right values but it doesn't execute the second request !! – leila.net Apr 22 '15 at 11:10
  • This is a common mistake done. Check this [http://stackoverflow.com/questions/4574606/c-sharp-dataadapter-and-dataset-with-multiple-table] – Shubhojit Apr 22 '15 at 11:16
  • thanks for your reply but in my situation I have to use 2 sql request!! – leila.net Apr 22 '15 at 11:21
  • try this & replace them with ur requirements, `SqlDataAdapter custAdapter = new SqlDataAdapter( "SELECT * FROM dbo.Customers", customerConnection); OleDbDataAdapter ordAdapter = new OleDbDataAdapter( "SELECT * FROM Orders", orderConnection); DataSet customerOrders = new DataSet(); custAdapter.Fill(customerOrders, "Customers"); ordAdapter.Fill(customerOrders, "Orders"); DataRelation relation = customerOrders.Relations.Add("CustOrders", customerOrders.Tables["Customers"].Columns["CustomerID"], customerOrders.Tables["Orders"].Columns["CustomerID"]);` – Shubhojit Apr 22 '15 at 11:57

0 Answers0