Exemplo n.º 1
0
 private static List<User> getUsers(SQLiteConnection conn)
 {
     var users = new List<User>();
     var command = new SQLiteCommand("select * from users", conn);
     var reader = command.ExecuteReader();
     while (reader.Read()) {
         var u = new User() { Username = reader["name"].ToString(), Firstname = reader["firstname"].ToString(), Lastname = reader["lastname"].ToString() };
         users.Add(u);
     }
     return users;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns>返回数据集</returns>
        public static List<User> Query()
        {

            try
            {
                StringBuilder strSQL = new StringBuilder();
                strSQL.AppendFormat("SELECT ID, name, email FROM user");
                SQLiteDBHelper sqliteDB = new SQLiteDBHelper();
                SQLiteDataReader reader = sqliteDB.ExecuteReader(strSQL.ToString());
                List<User> results = new List<User>();
                while (reader.Read())
                {
                    User user = new User();
                    user.ID = Convert.ToInt32(reader["ID"]);
                    user.name = reader["name"].ToString();
                    user.email = reader["email"].ToString();
                    results.Add(user);
                }
                return results;
            }
            catch
            {
                return null;
            }
        }