コード例 #1
0
        private void BindGrid()
        {
            string constr = ConfigurationManager.ConnectionStrings["StudentsConnectionString"].ConnectionString;

            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM Students"))
                {
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        cmd.Connection    = con;
                        sda.SelectCommand = cmd;
                        using (DataTable dt = new DataTable())
                        {
                            sda.Fill(dt);
                            Attendance.DataSource = dt;
                            Attendance.DataBind();
                        }
                    }
                }
            }
        }