public void create() { db = new Database(); path = new Path(); try { spaceQuery = new MySqlCommand(); spaceQuery.Connection = db.Connection(); spaceQuery.CommandText = "INSERT INTO space(spacedate,space,idpath) VALUES(@Date,@Space,@IDPath)"; spaceQuery.Prepare(); spaceQuery.Parameters.AddWithValue("@Date", spacedate); spaceQuery.Parameters.AddWithValue("@Space", space); spaceQuery.Parameters.AddWithValue("@IDPath", idpath); spaceQuery.ExecuteNonQuery(); //MessageBox.Show("O Espaço " + username + " foi criado com sucesso."); } catch (MySqlException ex) { MessageBox.Show("Ocurreu um erro"); Console.WriteLine("Error: {0}", ex.ToString()); } finally { db.Close(); } }
public Space() { path = new Path(); }
public void findByIDPath() { db = new Database(); path = new Path(); try { spaceQuery = new MySqlCommand(); spaceQuery.Connection = db.Connection(); spaceQuery.CommandText = "SELECT * FROM space WHERE idpath = @IDPath"; spaceQuery.Prepare(); spaceQuery.Parameters.AddWithValue("@IDPath", idpath); spaceResult = spaceQuery.ExecuteReader(); while (spaceResult.Read()) { if (!spaceResult.IsDBNull(0)) { idspace = spaceResult.GetInt32(0); } if (!spaceResult.IsDBNull(1)) { spacedate = spaceResult.GetDateTime(1); } if (!spaceResult.IsDBNull(2)) { space = spaceResult.GetInt64(2); } if (!spaceResult.IsDBNull(3)) { idpath = spaceResult.GetInt32(3); } spaces.Add(new Space { idspace = this.idspace, spacedate = this.spacedate, space = this.space, idpath = this.idpath }); } } catch (MySqlException ex) { Console.Write(ex.Message); } finally { db.Close(); } }