public bool UpdateStudent(Student stu) { if (con.State != ConnectionState.Open) { con.Open(); } using (SqlTransaction tran = con.BeginTransaction()) { try { //con.Open(); string query = "UPDATE Student SET StudentName='" + stu.StudentName + "',FatherName='" + stu.FatherName + "',MotherName='" + stu.MotherName + "',DateOfBirth='" + stu.DateOfBirth + "',AdmissionYear='" + stu.AdmissionYear + "',StudentCode='" + stu.StudentCode + "',DepartmentId='" + stu.DepartmentId + "',Hall='" + stu.Hall + "',Address='" + stu.Address + "',ContactNo='" + stu.ContactNo + "',Email='" + stu.Email + "',BloodGroup='" + stu.BloodGroup + "',Sex='" + stu.Sex + "',BioPhoto=@BioPhoto" + " WHERE StudentId='" + stu.StudentId + "'"; SqlCommand _command = new SqlCommand(); _command.Parameters.Add("@BioPhoto", SqlDbType.VarBinary).Value = stu.BioPhoto; _command.Transaction = tran; _command.CommandText = query; _command.Connection = con; _command.ExecuteNonQuery(); UserInfo usrobj = new UserInfo(); usrobj.EmpOrStdId = stu.StudentId; usrobj.UserName = stu.UserName; usrobj.Password = stu.Password; usrobj.UserTypeCode = 1; UserInfo_DBAccess db_usrinfo = new UserInfo_DBAccess(con, _command); db_usrinfo.UpdateUserInfo(usrobj); tran.Commit(); } catch { tran.Rollback(); return(false); } finally { if (con.State != ConnectionState.Closed) { con.Close(); } } } return(true); }
public bool UpdateEmployee(Employee emp) { if (con.State != ConnectionState.Open) { con.Open(); } using (SqlTransaction tran = con.BeginTransaction()) { try { // con.Open(); SqlCommand _command = new SqlCommand(); string query = "UPDATE Employee SET EmployeeName='" + emp.EmployeeName + "',EmployeeCode='" + emp.EmployeeCode + "',Address='" + emp.Address + "',ContactNo='" + emp.ContactNo + "',Email='" + emp.Email + "',BloodGroup='" + emp.BloodGroup + "',Sex='" + emp.Sex + "',JoiningDate='" + emp.JoiningDate + "',DepartmentId='" + emp.DepartmentId + "',BioPhoto=@BioPhoto" + " WHERE EmployeeId='" + emp.EmployeeId + "'"; _command.Parameters.Add("@BioPhoto", SqlDbType.VarBinary).Value = emp.BioPhoto; _command.CommandText = query; _command.Connection = con; _command.Transaction = tran; _command.ExecuteNonQuery(); UserInfo usrobj = new UserInfo(); usrobj.EmpOrStdId = emp.EmployeeId; usrobj.UserName = emp.UserName; usrobj.Password = emp.Password; usrobj.UserTypeCode = 2; UserInfo_DBAccess db_usrinfo = new UserInfo_DBAccess(con, _command); db_usrinfo.UpdateUserInfo(usrobj); tran.Commit();///my } catch { tran.Rollback(); return(false); } finally { if (con.State != ConnectionState.Closed) { con.Close(); } } } return(true); }