Exemplo n.º 1
0
        public void AddSV(QLSV sv)
        {
            string        sql = "INSERT INTO SINHVIEN(MaSV, HoTen, NgaySinh, GioiTinh, CMND, QueQuan, Lop, Khoa) VALUES('" + sv.MaSV + "', N'" + sv.HoTen + "',N'" + sv.NgaySinh + "',N'" + sv.GioiTinh + "','" + sv.CMND + "',N'" + sv.QueQuan + "','" + sv.Lop + "',N'" + sv.Khoa + "')";
            SqlConnection con = db.getConnection();
            SqlCommand    cmd = new SqlCommand(sql, con);

            con.Open();
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            con.Close();
        }
Exemplo n.º 2
0
        public List <QLSV> getQLSV(string MaSV)
        {
            string sql;

            if (string.IsNullOrEmpty(MaSV))
            {
                sql = "SELECT * FROM SINHVIEN ";
            }
            else
            {
                sql = "SELECT * FROM SINHVIEN WHERE MaSV = " + MaSV;
            }
            List <QLSV>    SVList = new List <QLSV>();
            DataTable      dt     = new DataTable();
            SqlConnection  con    = db.getConnection();
            SqlDataAdapter da     = new SqlDataAdapter(sql, con);

            con.Open();
            try
            {
                da.Fill(dt);
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                Console.WriteLine("Error: " + e.Message);
            }
            //da.Fill(dt);
            da.Dispose();
            con.Close();
            QLSV tmpSV;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                tmpSV          = new QLSV();
                tmpSV.MaSV     = dt.Rows[i]["MaSV"].ToString();
                tmpSV.HoTen    = dt.Rows[i]["HoTen"].ToString();
                tmpSV.NgaySinh = Convert.ToDateTime(dt.Rows[i]["NgaySinh"].ToString());
                tmpSV.GioiTinh = dt.Rows[i]["GioiTinh"].ToString();
                tmpSV.CMND     = Convert.ToInt32(dt.Rows[i]["CMND"].ToString());
                tmpSV.QueQuan  = dt.Rows[i]["QueQuan"].ToString();
                tmpSV.Lop      = dt.Rows[i]["Lop"].ToString();
                tmpSV.Khoa     = dt.Rows[i]["Khoa"].ToString();
                SVList.Add(tmpSV);
            }
            return(SVList);
        }