locked
Report using multiple tables in data adapter RRS feed

  • Question

  • User-1209090555 posted

    following is my code to generate report for multiple tables

    string val2="one";
    string val3 = "A";

    string SQL = "select * from tbl_batch,tbl_class,tbl_studentenrollment,tbl_section,tbl_student where tbl_batch.Batch_ID= tbl_studentenrollment.Batch_ID and tbl_student.Stu_ID = tbl_studentenrollment.Stu_ID and tbl_batch.Class_ID= tbl_class.Class_ID and tbl_batch.Sec_ID=tbl_section.Sec_ID and tbl_batch.Class_Name="+val2+" and tbl_batch.Sec_Name="+val3+"";
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = "Data Source=IMRAN-PC\\SQLEXPRESS; Initial Catalog=SMS; Trusted_Connection=True";

                conn.Open();

                SqlCommand cmd = new SqlCommand();

                SqlDataAdapter da = new SqlDataAdapter(SQL, conn);

                cmd.Connection = conn;

                cmd.CommandText = SQL;

                // cmd.ExecuteNonQuery();

                DataSet1 ds = new DataSet1();

                da.Fill(ds, "SQL"); // It works fine here for single table i.e. da.Fill(ds,"tbl_one"), HOw it will work multiple tables as i used i above query
               
                ReportDocument rd = new ReportDocument();

                rd.Load(Server.MapPath("~/" + "MyReport"));

                rd.SetDataSource(ds);

                CrystalReportViewer1.ReportSource = rd;

                CrystalReportViewer1.DataBind();

                conn.Close();

    Saturday, June 11, 2011 3:57 PM

Answers

  • User2119691303 posted

    The reason it is returning one table is because your SQL is returning one table.  If you want multiple tables in your dataset, change your SQL to return multiple tables - ie: make it multiple select statements.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 13, 2011 10:58 AM