//cap nhat category public void suaDanhMuc(danhMuc danhMuc) { conn.Open(); SqlCommand cmd = new SqlCommand("update danh_muc set tendanhmuc=N'" + danhMuc.tendanhmuc + "' where danhmuc=" + danhMuc.madanhmuc + "", conn); cmd.ExecuteNonQuery(); conn.Close(); }
// Tạo thêm danh mục public void themDanhMuc(danhMuc danhMuc) { conn.Open(); SqlCommand cmd = new SqlCommand("insert into danh_muc values(@ten)", conn); cmd.Parameters.AddWithValue("@ten", danhMuc.tendanhmuc); cmd.ExecuteNonQuery(); conn.Close(); }
// lấy dữ liệu danh mục public List <danhMuc> GetDanhMuc() { List <danhMuc> dsdanhmuc = new List <danhMuc>(); conn.Open(); SqlCommand cmd = new SqlCommand("select * from danh_muc", conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { danhMuc danhMuc = new danhMuc(); danhMuc.madanhmuc = (int)reader["danhmuc"]; danhMuc.tendanhmuc = (string)reader["tendanhmuc"]; dsdanhmuc.Add(danhMuc); } conn.Close(); return(dsdanhmuc); }
// lấy 1 danh mục public danhMuc get1danhMuc(int madanhmuc) { danhMuc danhMuc = new danhMuc(); conn.Open(); SqlCommand cmd = new SqlCommand("Select * From danh_muc where danhmuc=@madanhmuc", conn); cmd.Parameters.AddWithValue("@madanhmuc", madanhmuc); danhMuc = null; SqlDataReader rd = cmd.ExecuteReader(); if (rd.Read()) { danhMuc = new danhMuc(); danhMuc.madanhmuc = (int)rd["danhmuc"]; danhMuc.tendanhmuc = (string)rd["tendanhmuc"]; } conn.Close(); return(danhMuc); }