public SqlException Update(IsIn isin, int wardNumber) { string update = "UPDATE IsIn " + "SET Shift = @Shift, StaffNumber = @StaffNumber" + "WHERE Number = @wardNumber;"; // 1. declare command object with parameter + insert query SqlCommand cmd = InitializeDatabase.CreateSqlCommand(update); // 2. define parameters used in command object List <SqlParameter> prm = new List <SqlParameter>() { new SqlParameter("@Shift", SqlDbType.Int) { Value = isin.Shift }, new SqlParameter("@StaffNumber", SqlDbType.NVarChar) { Value = isin.StaffNumber }, new SqlParameter("@Number", SqlDbType.Int) { Value = isin.WardNumber } }; // 3. add new parameter to command object cmd.Parameters.AddRange(prm.ToArray()); //run SqlException res = InitializeDatabase.RunSqlCommand(cmd); return(res); }
public SqlException Create(IsIn isin) { //insert "Number" is ward number string insert = "INSERT INTO IsIn (Shift, StaffNumber, Number)" + " VALUES(@Shift, @StaffNumber, @Number); "; //create sql command, insert query, preparing quries, create parameterized quieries, // 1. declare command object with parameter + insert query SqlCommand cmd = InitializeDatabase.CreateSqlCommand(insert); // 2. define parameters used in command object List <SqlParameter> prm = new List <SqlParameter>() { new SqlParameter("@Shift", SqlDbType.NVarChar) { Value = isin.Shift }, new SqlParameter("@StaffNumber", SqlDbType.Int) { Value = isin.StaffNumber }, new SqlParameter("@Number", SqlDbType.Int) { Value = isin.WardNumber } }; // 3. add new parameter to command object cmd.Parameters.AddRange(prm.ToArray()); //run SqlException res = InitializeDatabase.RunSqlCommand(cmd); return(res); }