public void ThemSinhVien(DTOSinhVien SV) { OpenConnect(); string insert = "insert into [Sinhvien].[dbo].[SinhVien] values (@MaSV , @TenSV , @DiaChi , @SoDT)"; SqlCommand cmd = new SqlCommand(insert, conn); cmd.Parameters.Add(new SqlParameter("@MaSV", SV.MaSV)); cmd.Parameters.Add(new SqlParameter("@TenSV", SV.TenSV)); cmd.Parameters.Add(new SqlParameter("@DiaChi", SV.DiaChi)); cmd.Parameters.Add(new SqlParameter("@SoDT", SV.SoDT)); cmd.ExecuteNonQuery(); CloseConnect(); }
public void SuaSinhVien(DTOSinhVien SV) { OpenConnect(); string edit = "update [Sinhvien].[dbo].[SinhVien] set TenSV=@TenSV,DiaChi=@DiaChi, SoDT=@SoDT where MaSV=@MaSV"; SqlCommand cmd = new SqlCommand(edit, conn); cmd.Parameters.Add(new SqlParameter("@MaSV", SV.MaSV)); cmd.Parameters.Add(new SqlParameter("@TenSV", SV.TenSV)); cmd.Parameters.Add(new SqlParameter("@DiaChi", SV.DiaChi)); cmd.Parameters.Add(new SqlParameter("@SoDT", SV.SoDT)); cmd.ExecuteNonQuery(); CloseConnect(); }
private void btnThem_Click(object sender, EventArgs e) { DTOSinhVien SV = new DTOSinhVien(txtMaSV.Text, txtTenSV.Text, txtDiaChi.Text, txtSoDT.Text); try { bosinhvien.ThemSinhVien(SV); LoadData(); xoatextbox(); MessageBox.Show("thêm thành công"); } catch { MessageBox.Show("thêm thành công"); } }