public RiderItem GetRiderItem(int riderNo) { SQLiteCommand query = new SQLiteCommand(); query.CommandText = "SELECT rider_no, rider_first, rider_last, rider_dob, phone, email, member, rider_comment " + "FROM [" + Year + "_rider] WHERE rider_no = @noparam;"; query.CommandType = System.Data.CommandType.Text; query.Parameters.Add(new SQLiteParameter("@noparam", riderNo)); query.Connection = ClubConn; SQLiteDataReader reader = DoTheReader(query); RiderItem item = new RiderItem(); while (reader.Read()) { item.No = reader.GetInt32(0); item.FirstName = reader.GetString(1); item.LastName = reader.GetString(2); item.Birthdate = StringToDate(reader.GetString(3)); item.Phone = reader.GetString(4); item.Email = reader.GetString(5); item.Member = (bool)IntToBool(reader.GetInt32(6)); item.Comments = reader.GetString(7); } reader.Close(); ClubConn.Close(); return item; }
// Optional: sort (default is rider_last) public List<RiderItem> GetRiderItemList(RiderSort sort = RiderSort.Default) { // Case statment for sort column string sortString; switch (sort) { case RiderSort.Number: sortString = "rider_no"; break; case RiderSort.FirstName: sortString = "rider_first, rider_last"; break; case RiderSort.BirthDate: sortString = "rider_dob, rider_last"; break; default: sortString = "rider_last, rider_first"; break; } string query = "SELECT rider_no, rider_first, rider_last, rider_dob, phone, email, member, rider_comment FROM [" + Year + "_rider] ORDER BY " + sortString + ";"; SQLiteDataReader reader = DoTheReader(ClubConn, query); List<RiderItem> riderItemList = new List<RiderItem>(); RiderItem item; reader = DoTheReader(ClubConn, query); while (reader.Read()) { item = new RiderItem(); item.No = reader.GetInt32(0); item.FirstName = reader.GetString(1); item.LastName = reader.GetString(2); item.Birthdate = StringToDate(reader.GetString(3)); item.Phone = reader.GetString(4); item.Email = reader.GetString(5); item.Member = (bool)IntToBool(reader.GetInt32(6)); item.Comments = reader.GetString(7); riderItemList.Add(item); } reader.Close(); ClubConn.Close(); return riderItemList; }
// Optional: sort (default is rider_last) public List<RiderItem> GetRiderItemList(string database, int year, string sort) { MySqlDataReader reader; RiderItem item; List<RiderItem> riderItemList = new List<RiderItem>(); if (sort == "rider_last" || sort == String.Empty) sort = "rider_last, rider_first"; reader = GetReader(database, year + "_rider", "rider_no, first_name, last_name, rider_dob, phone, email, member", String.Empty, sort); while (reader.Read()) { item = new RiderItem(); item.no = reader.GetInt32(0); item.firstName = reader.GetString(1); item.lastName = reader.GetString(2); item.dob = reader.GetString(3); item.phone = reader.GetString(4); item.email = reader.GetString(5); item.member = reader.GetBoolean(6); riderItemList.Add(item); } reader.Close(); connection.Close(); return riderItemList; }