public void InsertSanctionType(SanctionType stype) { using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(INSERT_SANCTIONTYPE, conn); /* Add parameters into the command */ command.Parameters.AddWithValue("@stype_name", stype.stype_name); command.Parameters.AddWithValue("@stype_ammount", stype.stype_ammount); /* Executes the command */ command.ExecuteNonQuery(); } }
public List<SanctionType> SelectAll() { List<SanctionType> stypeList = new List<SanctionType>(); using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(SELECT_ALL, conn); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { SanctionType stype = new SanctionType(); stype.stype_id = reader.GetInt32(0); stype.stype_ammount = reader.GetInt32(1); stype.stype_name = reader.GetString(2); stypeList.Add(stype); } } return stypeList; }
public SanctionType SelectOne(int stypeId) { SanctionType stype = new SanctionType(); using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(SELECT_ONE, conn); command.Parameters.AddWithValue("@stype_id", stypeId); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { stype.stype_id = reader.GetInt32(0); stype.stype_name = reader.GetString(1); stype.stype_ammount = reader.GetInt32(2); } reader.Close(); } return stype; }
public void Update(SanctionType stype) { using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(UPDATE_SANCTIONTYPE, conn); command.Parameters.AddWithValue("@stype_id", stype.stype_id); command.Parameters.AddWithValue("@stype_name", stype.stype_name); command.Parameters.AddWithValue("@stype_ammount", stype.stype_ammount); /* Executes the command */ command.ExecuteNonQuery(); } }
protected void Button5_Click(object sender, EventArgs e) { //prida typ sankce DatabaseLibrary.SanctionType stype = new DatabaseLibrary.SanctionType(); stype.stype_ammount = Convert.ToInt32(TextBox_stype_ammount.Text); stype.stype_name = TextBox_stype_name.Text; new DatabaseLibrary.SanctionTypeTable().InsertSanctionType(stype); Response.Redirect(Request.RawUrl); }