Пример #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();

        con.ConnectionString = WebConfigurationManager.ConnectionStrings["mainDB"].ConnectionString;
        string query = "SELECT SID,Student.Department AS Department,Section,Teacher.Name AS Name,count(*) AS Total FROM Student LEFT JOIN Teacher ON Student.TID = Teacher.TID GROUP BY SID,Student.Department,Section,Teacher.Name;";

        try
        {
            con.Open();
            SqlCommand     cmd     = new SqlCommand(query, con);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet        ds      = new DataSet();
            adapter.Fill(ds, "SlotsInfo");
            ShowSlotsGV.DataSource = ds;
            ShowSlotsGV.DataBind();
        }
        catch (Exception err)
        {
            errLabel.Text = "Unable to fetch data! " + err;
        }
        finally
        {
            con.Close();
        }
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         SqlConnection con = new SqlConnection();
         con.ConnectionString = WebConfigurationManager.ConnectionStrings["mainDB"].ConnectionString;
         string query        = "SELECT SID,Student.Department AS Department,Section,count(*) AS Total FROM Student FULL OUTER JOIN Teacher ON Student.TID = Teacher.TID GROUP BY SID,Student.Department,Section,Teacher.Name HAVING Teacher.Name IS NULL;";
         string filled_query = "SELECT SID,Teacher.Name AS Name,Student.Department AS Department,Section,count(*) AS Total FROM Student INNER JOIN Teacher ON Student.TID = Teacher.TID GROUP BY SID,Student.Department,Section,Teacher.Name HAVING Teacher.Name IS NOT NULL;";
         try
         {
             con.Open();
             SqlCommand     cmd     = new SqlCommand(query, con);
             SqlDataAdapter adapter = new SqlDataAdapter(cmd);
             DataSet        ds      = new DataSet();
             adapter.Fill(ds, "SlotsInfo");
             ShowSlotsGV.DataSource = ds.Tables["SlotsInfo"];
             ShowSlotsGV.DataBind();
             cmd.CommandText = filled_query;
             adapter.Fill(ds, "FilledSlotsInfo");
             FilledGV.DataSource = ds.Tables["FilledSlotsInfo"];
             FilledGV.DataBind();
         }
         catch (Exception err)
         {
             errLabel.Text = "Unable to fetch data! " + err;
         }
         finally
         {
             con.Close();
         }
     }
 }