public bool Update(TeacherBase mClass) { bool mResult = false; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["csSwim"].ConnectionString); string sql = "UPDATE Teacher SET FirstName = @FirstName, LastName = @LastName, Phone = @Phone, Mobile = @Mobile, Email = @Email, Password = @Password, IsActive = @IsActive " + "WHERE TeacherId = @TeacherId;"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.Add("@TeacherId", SqlDbType.Int).Value = mClass.TeacherId; cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = mClass.FirstName; cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = mClass.LastName; cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = mClass.Phone; cmd.Parameters.Add("@Mobile", SqlDbType.VarChar).Value = mClass.Mobile; cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = mClass.Email; cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = mClass.Password; cmd.Parameters.Add("@IsActive", SqlDbType.Bit).Value = mClass.IsActive; try { con.Open(); cmd.ExecuteNonQuery(); mResult = true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { con.Close(); con.Dispose(); cmd.Dispose(); } return(mResult); }
public int Add(TeacherBase mClass) { int TeacherId = 0; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["csSwim"].ConnectionString); string sql = "INSERT INTO Teacher (FirstName, LastName, Phone, Mobile, Email, Password, IsActive)" + " VALUES (@FirstName, @LastName, @Phone, @Mobile, @Email, @Password, @IsActive)" + " SELECT SCOPE_IDENTITY()"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = mClass.FirstName; cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = mClass.LastName; cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = mClass.Phone; cmd.Parameters.Add("@Mobile", SqlDbType.VarChar).Value = mClass.Mobile; cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = mClass.Email; cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = mClass.Password; cmd.Parameters.Add("@IsActive", SqlDbType.Bit).Value = mClass.IsActive; try { con.Open(); TeacherId = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { TeacherId = -1; Console.WriteLine(ex.ToString()); } finally { con.Close(); con.Dispose(); cmd.Dispose(); } return(TeacherId); }
private TeacherBase Get(string WhereClause, params SqlParameter[] commandparameters) { TeacherBase mClass = null; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["csSwim"].ConnectionString); string sql = "SELECT db.TeacherId, db.FirstName, db.LastName, db.Phone, db.Mobile, db.Email, db.Password, db.IsActive, db.Created " + "FROM Teacher db " + WhereClause; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader rdr = null; foreach (var parameter in commandparameters) { cmd.Parameters.Add(parameter); } try { con.Open(); rdr = cmd.ExecuteReader(); if (rdr.Read()) { mClass = LoadRow(rdr); } } catch (Exception ex) { mClass = null; Console.WriteLine(ex.ToString()); } finally { con.Close(); con.Dispose(); cmd.Dispose(); } return(mClass); }
private void Populate(TeacherBase mClass) { this.TeacherId = mClass.TeacherId; this.FirstName = mClass.FirstName; this.LastName = mClass.LastName; this.Phone = mClass.Phone; this.Mobile = mClass.Mobile; this.Email = mClass.Email; this.Password = mClass.Password; this.IsActive = mClass.IsActive; this.Created = mClass.Created; }