public void addNewRecrute(Recrute r) { try { conn.Open(); string insertRec = "INSERT INTO RECUIT (RecuitName, price, Health, Speed, Attack, Defence) VALUES (?,?,?,?,?,?)"; comm = new OleDbCommand(insertRec, conn); OleDbParameter paramN = new OleDbParameter("RecuitName", r.RecuitName); OleDbParameter paramP = new OleDbParameter("price", r.Price); OleDbParameter paramH = new OleDbParameter("Health", r.Health); OleDbParameter paramS = new OleDbParameter("Speed", r.Speed); OleDbParameter paramA = new OleDbParameter("Attack", r.Attack); OleDbParameter paramD = new OleDbParameter("Defence", r.Defence); comm.Parameters.Add(paramN); comm.Parameters.Add(paramP); comm.Parameters.Add(paramH); comm.Parameters.Add(paramS); comm.Parameters.Add(paramA); comm.Parameters.Add(paramD); comm.ExecuteNonQuery(); } catch (Exception ex) { } }
public List <Recrute> getRecuitFromDB() { List <Recrute> allRecute = new List <Recrute>(); string selectRec = "SELECT * FROM RECUIT"; comm = new OleDbCommand(selectRec, conn); recruteReader = comm.ExecuteReader(CommandBehavior.CloseConnection); while (recruteReader.Read()) { string id = recruteReader["RecuitID"].ToString(); string rName = recruteReader["RecuitName"].ToString(); string price = recruteReader["price"].ToString(); string health = recruteReader["Health"].ToString(); string speed = recruteReader["Speed"].ToString(); string Attack = recruteReader["Attack"].ToString(); string def = recruteReader["Defence"].ToString(); string Picn = recruteReader["PicName"].ToString(); Recrute r = new Recrute(id, rName, price, health, speed, Attack, def, Picn); allRecute.Add(r); } recruteReader.Close(); return(allRecute); }
private void btnAdd_Click(object sender, EventArgs e) { addingNew = true; Recrute newRecrute = new Recrute(); roster.Add(newRecrute); recruteBindingSource.MoveLast(); }
public void deleteRecruteFromDB(Recrute r) { conn.Open(); string deleteRec = "DELETE FROM RECUIT WHERE RecuitID=?"; comm = new OleDbCommand(deleteRec, conn); OleDbParameter pramID = new OleDbParameter("RecuitID", r.RecuitID); //placeing in to the placeholder of deleteStue var comm.Parameters.Add(pramID); //letting the them know about eachother comm.ExecuteNonQuery(); conn.Close(); }
private void recruteBindingSource_CurrentChanged(object sender, EventArgs e) { picBox.Image = null; currentRecrute = (Recrute)recruteBindingSource.Current; try { if (currentRecrute != null) { if (currentRecrute.PicName != "") { picBox.Image = Image.FromFile(currentRecrute.PicName); } } } catch (Exception ex) { } }
public void addPic(Recrute r) { try { conn.Open(); string insertPic = "INSERT INTO RECUIT (PicName) VALUES (?)"; comm = new OleDbCommand(insertPic, conn); OleDbParameter paramPic = new OleDbParameter("PicName", r.PicName); comm.Parameters.Add(paramPic); comm.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { } }
public void editRecrute(Recrute r) { try { conn.Open(); string updateRec = "UPDATE RECUIT SET " + "RecuitName=?, " + "price=?, " + "Health=?, " + "Speed=?, " + "Attack=?, " + "Defence=? " + "WHERE RecuitID=?"; comm = new OleDbCommand(updateRec, conn); OleDbParameter paramN = new OleDbParameter("RecuitName", r.RecuitName); OleDbParameter paramP = new OleDbParameter("price", r.Price); OleDbParameter paramH = new OleDbParameter("Health", r.Health); OleDbParameter paramS = new OleDbParameter("Speed", r.Speed); OleDbParameter paramA = new OleDbParameter("Attack", r.Attack); OleDbParameter paramD = new OleDbParameter("Defence", r.Defence); comm.Parameters.Add(paramN); comm.Parameters.Add(paramP); comm.Parameters.Add(paramH); comm.Parameters.Add(paramS); comm.Parameters.Add(paramA); comm.Parameters.Add(paramD); comm.ExecuteNonQuery(); conn.Close(); } catch (Exception e) { } }
private void btnEdit_Click(object sender, EventArgs e) { rec = new Recrute(recuitNameTextBox.Text, priceTextBox.Text, healthTextBox.Text, speedTextBox.Text, attackTextBox.Text, defenceTextBox.Text, picNameTextBox.Text); }