public List <IHistoryWord> GetAllFriends() { var list = new List <IHistoryWord>(); using (SQLiteConnection conn = new SQLiteConnection(ConnectionString)) { conn.Open(); string sqlInsert = $@"SELECT * FROM HistoryWord"; using (SQLiteCommand cmd = new SQLiteCommand(sqlInsert, conn)) { using (SQLiteDataAdapter da = new SQLiteDataAdapter(cmd)) { var dataTable = new DataTable(); da.Fill(dataTable); foreach (DataRow row in dataTable.Rows) { var historyWord = new HistoryWord(); historyWord.Id = row["Id"].ToString(); historyWord.Times = (uint)row["Times"]; historyWord.Word = row["Word"] != null ? row["Word"].ToString() : string.Empty; historyWord.Translate = row["Translate"] != null ? row["Translate"].ToString() : string.Empty; list.Add(historyWord); } } } } return(list); }
public IHistoryWord GetFriendById(string id) { HistoryWord historyWord = null; using (SQLiteConnection conn = new SQLiteConnection(ConnectionString)) { conn.Open(); string sqlInsert = $@"SELECT * FROM HistoryWord WHERE Id='{id}'"; using (SQLiteCommand cmd = new SQLiteCommand(sqlInsert, conn)) { SQLiteDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { historyWord = new HistoryWord(); historyWord.Id = dr["Id"].ToString(); historyWord.Times = (uint)dr["Name"]; historyWord.Word = dr["Email"] != null ? dr["Email"].ToString() : string.Empty; historyWord.Translate = dr["Translate"] != null ? dr["Translate"].ToString() : string.Empty; } } } return(historyWord); }