Lớp Môn Học

public class MonHoc

    {

        private string _MaMH;

 

        public string MaMH

        {

           get { return _MaMH; }

            set { _MaMH = value; }

        }

        private string _TenMH;

 

        public string TenMH

        {

            get { return _TenMH; }

            set { _TenMH = value; }

        }

        private int _Sotiet;

 

        public int Sotiet

        {

            get { return _Sotiet; }

            set { _Sotiet = value; }

        }

Lớp Môn Học




Lấy danh sách các môn học

public static List<MonHoc> MonHocLayTatCa()

        {

            List<MonHoc> list = new List<MonHoc>();

            using (SqlConnection cnn = Helpers.GetSqlconnection())

            {

                SqlCommand cmd = cnn.CreateCommand();

                cmd.CommandText = "MonHoc_LayTatCa";

                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cnn.Open();

                SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

                while (dr.Read())

                {

                    MonHoc mh = new MonHoc();

                    mh.MaMH = dr["MaMH"].ToString();

                    mh.TenMH = dr["TenMH"].ToString();

                    mh.Sotiet = ChangeType.Toin32(dr["SoTiet"]);                  

                    list.Add(mh);

                }

                dr.Close();

            }

            return list;

      }

Thêm môn học

public static int MonHocThem(MonHoc mh)

        {

            using (SqlConnection cnn = Helpers.GetSqlconnection())

            {

                SqlCommand cmd = cnn.CreateCommand();

                cmd.CommandText = "MonHoc_Them";

                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cnn.Open();

 

                cmd.Parameters.Add("@MaMH", System.Data.SqlDbType.NVarChar, 8).Value = mh.MaMH;

                cmd.Parameters.Add("@TenMH", System.Data.SqlDbType.NVarChar, 50).Value = mh.TenMH;

                cmd.Parameters.Add("@SoTiet", System.Data.SqlDbType.Int).Value = mh.Sotiet;

 

                int rs = cmd.ExecuteNonQuery();

 

 

                cnn.Close();

                return rs;

            }

 

        }


Đăng nhận xét

Post a Comment (0)

Mới hơn Cũ hơn