// Method to update data in DB from our application public bool Update(Pombo p) { // Create default return type and set its value to false bool isSuccessful = false; // Connect DB SQLiteConnection connection = new SQLiteConnection(myConStr); try { // SQL to update data in our DB string sql = "UPDATE TablePombos SET Número=@Número, Nome=@Nome, Data=@Data, Género=@Género, NúmeroPai=@NúmeroPai, NúmeroMãe=@NúmeroMãe, Estado=@Estado, Imagem=@Imagem WHERE ID=@ID"; // Create SQL command using SQL and connection SQLiteCommand cmd = new SQLiteCommand(sql, connection); // Create parameters to add data cmd.Parameters.AddWithValue("@Número", p.Number); cmd.Parameters.AddWithValue("@Nome", p.Name); cmd.Parameters.AddWithValue("@Data", p.Date); cmd.Parameters.AddWithValue("@Género", p.Gender); cmd.Parameters.AddWithValue("@NúmeroPai", p.DadNumber); cmd.Parameters.AddWithValue("@NúmeroMãe", p.MomNumber); cmd.Parameters.AddWithValue("@Estado", p.State); cmd.Parameters.AddWithValue("@Imagem", p.Image); cmd.Parameters.AddWithValue("ID", p.PomboID); // Connection open connection.Open(); int rows = cmd.ExecuteNonQuery(); // If the Query runs successfully then the value of rows will be greater than zero, else its value is zero if (rows > 0) { // Success isSuccessful = true; } else { // Error isSuccessful = false; } } catch (Exception e) { MessageBox.Show(e.ToString()); } finally { connection.Close(); } return(isSuccessful); }
// Insert data into DB public bool Insert(Pombo p) { // Create default return type and set its value to false bool isSuccessful = false; // Connect DB SQLiteConnection connection = new SQLiteConnection(myConStr); try { // Create SQL Query to insert data string sql = "INSERT INTO TablePombos (Número, Nome, Data, Género, NúmeroPai, NúmeroMãe, Estado, Notas, Imagem) VALUES (@Número, @Nome, @Data, @Género, @NúmeroPai, @NúmeroMãe, @Estado, @Notas, @Imagem)"; // Create SQL command using SQL and connection SQLiteCommand cmd = new SQLiteCommand(sql, connection); // Create parameters to add data cmd.Parameters.AddWithValue("@Número", p.Number); cmd.Parameters.AddWithValue("@Nome", p.Name); cmd.Parameters.AddWithValue("@Data", p.Date); cmd.Parameters.AddWithValue("@Género", p.Gender); cmd.Parameters.AddWithValue("@NúmeroPai", p.DadNumber); cmd.Parameters.AddWithValue("@NúmeroMãe", p.MomNumber); cmd.Parameters.AddWithValue("@Estado", p.State); cmd.Parameters.AddWithValue("@Notas", p.Notes); cmd.Parameters.AddWithValue("@Imagem", p.Image); // Connection open connection.Open(); int rows = cmd.ExecuteNonQuery(); // If the Query runs successfully then the value of rows will be greater than zero, else its value is zero if (rows > 0) { // Success isSuccessful = true; } else { // Error isSuccessful = false; } } catch (Exception e) { MessageBox.Show(e.ToString()); } finally { connection.Close(); } return(isSuccessful); }
// Method to delete data in DB from our application public bool Delete(Pombo p) { // Create default return type and set its value to false bool isSuccessful = false; // Connect DB SQLiteConnection connection = new SQLiteConnection(myConStr); try { // SQL to delete data in our DB string sql = "DELETE FROM TablePombos WHERE ID=@ID"; // Create SQL command using SQL and connection SQLiteCommand cmd = new SQLiteCommand(sql, connection); // Create parameters to add data cmd.Parameters.AddWithValue("@ID", p.PomboID); // Connection open connection.Open(); int rows = cmd.ExecuteNonQuery(); // If the Query runs successfully then the value of rows will be greater than zero, else its value is zero if (rows > 0) { // Success isSuccessful = true; } else { // Error isSuccessful = false; } } catch (Exception e) { MessageBox.Show(e.ToString()); } finally { connection.Close(); } return(isSuccessful); }