public static DBPrecinctCouncilors GetDataByPrecinct(string precinct, string municipality, int candidate_id) { DBPrecinctCouncilors data = null; SQLiteConnection con = DBConnection.ConnectDatabase(); try { SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM " + tablename + " WHERE precinct='" + precinct + "' AND municipality='" + municipality + "' AND candidate_id=" + candidate_id, con); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); data = new DBPrecinctCouncilors(); data.Id = reader.GetInt32(0); data.Municipality = reader.GetString(1); data.Precinct = reader.GetString(2); data.Votes = reader.GetInt32(3); data.Candidate_id = reader.GetInt32(4); } reader.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } return(data); }
public static List <DBPrecinctCouncilors> SumationDataTabulation(string municipality) { List <DBPrecinctCouncilors> data = new List <DBPrecinctCouncilors>(); SQLiteConnection con = DBConnection.ConnectDatabase(); try { SQLiteCommand cmd = new SQLiteCommand("SELECT candidate_id,SUM(votes) FROM " + tablename + " WHERE municipality='" + municipality + "' GROUP by candidate_id", con); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { DBPrecinctCouncilors rawData = new DBPrecinctCouncilors(); rawData.Candidate_id = reader.GetInt32(0); rawData.Votes = reader.GetInt32(1); data.Add(rawData); } } reader.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } return(data); }