Ok so I have a class for all my database connections, what I want to do is populate my gridview from my select statment within my database class. How do I do this?

Code can be seen below:

Database.cs

  public static string DeleteChild(string Ssession)
        {
            string surname = string.Empty;

            cmd = new SqlCommand("Select Forename,Surname,DOB,Username from Children WHERE fkParentID = (select ParentID from Users Where Username = '" + Ssession + "')", con);
            cmd.Connection = con;
            cmd.Parameters.AddWithValue("@username", Ssession);
            con.Open();
            surname = cmd.ExecuteScalar().ToString();
            con.Close();
            return surname;
        }

GridView.aspx.cs

protected void Details()
        {
            con.Open();

           // string b = Session["LoginSession"].ToString();
            //string forename = DBdatabase.DeleteChild(b);

            SqlCommand cmd = new SqlCommand("Select Forename,Surname,DOB,Username from Children WHERE fkParentID = (select ParentID from Users Where Username = '" + Session["LoginSession"] + "')", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            con.Close();
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
            else
            {
                ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
                GridView1.DataSource = ds;
                GridView1.DataBind();
                int columncount = GridView1.Rows[0].Cells.Count;
                GridView1.Rows[0].Cells.Clear();
                GridView1.Rows[0].Cells.Add(new TableCell());
                GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
                GridView1.Rows[0].Cells[0].Text = "No Records Found";
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.