当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteCommand.ExecuteReaderAsync方法代码示例

本文整理汇总了C#中System.Data.SQLite.SQLiteCommand.ExecuteReaderAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteCommand.ExecuteReaderAsync方法的具体用法?C# SQLiteCommand.ExecuteReaderAsync怎么用?C# SQLiteCommand.ExecuteReaderAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SQLite.SQLiteCommand的用法示例。


在下文中一共展示了SQLiteCommand.ExecuteReaderAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        public async Task Load(SQLiteConnection connection)
        {
            using (var command = new SQLiteCommand("SELECT * FROM `Tracks`", connection))
            {
                var reader = await command.ExecuteReaderAsync();
                while (await reader.ReadAsync())
                {
                    PlayableBase track;
                    using (var xmlReader = reader.GetTextReader(8))
                        track = (PlayableBase) _serializer.Deserialize(xmlReader);

                    track.Title = reader.GetString(0);
                    track.Artist = _artistProvider.ArtistDictionary[reader.ReadGuid(1)];

                    var albumGuid = reader.ReadGuid(2);
                    if (albumGuid != Guid.Empty)
                        track.Album = _albumsProvider.Collection[albumGuid];
                    track.Guid = reader.ReadGuid(3);
                    track.LastTimePlayed = reader.GetDateTime(4);
                    track.MusicBrainzId = reader.GetValue(5)?.ToString();
                    track.Duration = XmlConvert.ToTimeSpan(reader.GetString(6));

                    var coverId = reader.ReadGuid(7);
                    if (coverId != Guid.Empty)
                        track.Cover = _imageProvider.Collection[coverId];

                    Collection.Add(track.Guid, track);
                    Tracks.Add(track);
                }
            }

            _connection = connection;
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:33,代码来源:TrackProvider.cs

示例2: GetDataAsync

        public async Task<List<InventurItem>> GetDataAsync()
        {
            //using (var db = new InventurContext())
            //{
            //    return await (from i in db.InventurItems
            //                  where i.Exported == false
            //                  orderby i.ChangedAt descending
            //                  select i).ToListAsync();
            //}

            using (var command = new SQLiteCommand($"select * from {TABNAME} where Exported=0 orderby ChangedAt DESC", _dbTool.ConnectDb()))
            {
                using (var reader = await command.ExecuteReaderAsync())
                {
                    var items = new List<InventurItem>();
                    if (await reader.ReadAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var i = new InventurItem { ID = Convert.ToInt32(reader["ID"]), CreatedAt = Convert.ToDateTime(reader["CreatedAt"]), ChangedAt = Convert.ToDateTime(reader["ChangedAt"]), EANCode = reader["EANCode"].ToString(), Amount = Convert.ToInt32(reader["Amount"]), Exported = Convert.ToBoolean(reader["Exported"]) };
                            items.Add(i);
                        }
                    }
                    return items;
                }
            }
        }
开发者ID:mprattinger,项目名称:Inventur,代码行数:27,代码来源:DataService.cs

示例3: Load

        public async Task Load(SQLiteConnection connection)
        {
            using (var command = new SQLiteCommand("SELECT * FROM `Albums`", connection))
            {
                var reader = await command.ExecuteReaderAsync();
                while (await reader.ReadAsync())
                {
                    var album = new Album
                    {
                        Name = reader.GetString(0),
                        Guid = reader.ReadGuid(1),
                        Artists =
                            new ObservableCollection<Artist>(
                                reader.GetString(2)?
                                    .Split( ',')
                                    .Where(x => !string.IsNullOrWhiteSpace(x))
                                    .Select(x => _artistProvider.ArtistDictionary[Guid.ParseExact(x, "D")]) ??
                                new List<Artist>())
                    };

                    Collection.Add(album.Guid, album);
                }
            }

            _connection = connection;
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:26,代码来源:AlbumsProvider.cs

示例4: GetTodos

        public async Task<ObservableCollection<Todo>> GetTodos()
        {
            using (var conn = new SQLiteConnection("Data Source=TodoList.s3db"))
            {
                using (var cmd = new SQLiteCommand("SELECT * FROM TODOs", conn))
                {
                    await conn.OpenAsync();
                    using (var reader = await cmd.ExecuteReaderAsync())
                    {
                        if (!reader.HasRows)
                        {
                            return new ObservableCollection<Todo>();
                        }

                        var todos = new ObservableCollection<Todo>();
                        Todo todo = null;
                        while (reader.Read())
                        {
                            todo = new Todo();
                            todo.Id = Convert.ToInt32(reader["Id"].ToString());
                            todo.CreateDate = Convert.ToDateTime(reader["CreateDate"].ToString());
                            todo.Task = reader["Task"].ToString();
                            todo.Done = Convert.ToBoolean(reader["Done"].ToString());
                            todo.DueDate = reader["DueDate"] == DBNull.Value ?
                                null as DateTime? : Convert.ToDateTime(reader["DueDate"].ToString());
                            todos.Add(todo);
                        }
                        return todos;
                    }
                }
            }
        }
开发者ID:alwalker,项目名称:TodoList,代码行数:32,代码来源:TodoDAO.cs

示例5: Load

        public async Task Load(SQLiteConnection connection)
        {
            using (var command = new SQLiteCommand("SELECT * FROM `Artists`", connection))
            {
                var reader = await command.ExecuteReaderAsync();
                while (await reader.ReadAsync())
                {
                    var id = reader.ReadGuid(3);
                    Artist artist;
                    if (id == UnknownArtistGuid)
                        artist = UnknownArtist;
                    else
                    {
                        artist = new Artist
                        {
                            Name = reader.GetString(0),
                            MusicBrainzId = reader.GetValue(1)?.ToString(),
                            Url = reader.GetValue(2)?.ToString(),
                            Guid = id
                        };
                    }

                    var temp = reader.ReadGuid(4);
                    if (temp != Guid.Empty)
                        artist.SmallImage = _imageProvider.Collection[temp];
                    temp = reader.ReadGuid(5);
                    if (temp != Guid.Empty)
                        artist.MediumImage = _imageProvider.Collection[temp];
                    temp = reader.ReadGuid(6);
                    if (temp != Guid.Empty)
                        artist.LargeImage = _imageProvider.Collection[temp];

                    ArtistDictionary.Add(artist.Guid, artist);
                    if (artist.Guid == UnknownArtistGuid)
                        UnknownArtist = artist;
                }
            }

            _connection = connection;
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:40,代码来源:ArtistProvider.cs

示例6: Load

        public async Task Load(SQLiteConnection connection)
        {
            using (var command = new SQLiteCommand("SELECT * FROM `Images`", connection))
            {
                var reader = await command.ExecuteReaderAsync();
                while (await reader.ReadAsync())
                {
                    var id = reader.ReadGuid(1);
                    switch (reader.GetInt32(0))
                    {
                        case 0:
                            Collection.Add(id, new TagImage(reader.GetString(2)));
                            break;
                        case 1:
                            Collection.Add(id, new OnlineImage(reader.GetString(2)));
                            break;
                    }
                }
            }

            _connection = connection;
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:22,代码来源:ImagesProvider.cs

示例7: Load

        public async Task Load(SQLiteConnection connection)
        {
            using (var command = new SQLiteCommand("SELECT * FROM `Playlists`", connection))
            {
                var reader = await command.ExecuteReaderAsync();
                while (await reader.ReadAsync())
                {
                    var playlist = new UserPlaylist {Name = reader.GetString(0), Id = reader.GetGuid(1)};
                    using (var trackCommando = new SQLiteCommand("SELECT * FROM `PlaylistTracks` WHERE [email protected]", connection ))
                    {
                        trackCommando.Parameters.AddGuid("@guid", playlist.Id);
                        var trackReader = trackCommando.ExecuteReader();
                        while (await trackReader.ReadAsync())
                            playlist.Tracks.Add(_trackProvider.Collection[trackReader.GetGuid(1)]);
                    }
                    playlist.TrackAdded += Playlist_TrackAdded;
                    playlist.TrackRemoved += Playlist_TrackRemoved;

                    Playlists.Add(playlist);
                }
            }

            _connection = connection;
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:24,代码来源:PlaylistProvider.cs

示例8: GetStatisticEntriesAsync

        public async Task<List<StatisticsEntry>> GetStatisticEntriesAsync(int limit)
        {
            Connection.Open();

            List<StatisticsEntry> ret = new List<StatisticsEntry>();
            SQLiteCommand command = new SQLiteCommand("SELECT ID, Timestamp, Runtime, CurrentPlayers, TotalPlayers, CurrentMemory, MaximumMemory, Restarts FROM statistics ORDER BY Timestamp DESC Limit $limit", Connection);
            command.Parameters.AddWithValue("$limit", limit);
            DbDataReader reader = await command.ExecuteReaderAsync();

            while (reader.Read())
            {
                int ID = Convert.ToInt32(reader["ID"]);
                DateTime Timestamp = (DateTime)reader["Timestamp"];
                TimeSpan Runtime = TimeSpan.Parse(reader.GetString(2));
                int CurrentPlayers = Convert.ToInt32(reader["CurrentPlayers"]);
                int TotalPlayers = Convert.ToInt32(reader["TotalPlayers"]);
                long CurrentMemory = Convert.ToInt64(reader["CurrentMemory"]);
                long MaxMemory = Convert.ToInt64(reader["MaximumMemory"]);
                int Restarts = Convert.ToInt32(reader["Restarts"]);

                StatisticsEntry tmp = new StatisticsEntry(ID, Timestamp, Runtime, CurrentPlayers, TotalPlayers, CurrentMemory, MaxMemory, Restarts);
                ret.Add(tmp);
            }

            reader.Close();

            Connection.Close();
            return ret;
        }
开发者ID:ChrisK91,项目名称:CWSRestart,代码行数:29,代码来源:Statistics.cs

示例9: GetKnownNamesAsync

        /// <summary>
        /// Retreives a list of known names for an IP (async)
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public async Task<List<string>> GetKnownNamesAsync(string IP)
        {
            await Connection.OpenAsync();

            List<string> ret = new List<string>();
            long ipId = await getIPIDAsync(IP, true);

            SQLiteCommand command = new SQLiteCommand("SELECT COUNT(*) FROM knownPlayers WHERE IP = $ip");
            command.Parameters.AddWithValue("$ip", ipId);

            long count = (long)await ExecuteScalarAsync(command);

            if (count > 0)
            {
                //await connection.OpenAsync();

                command = new SQLiteCommand("SELECT names.Name as Name FROM knownPlayers LEFT JOIN names ON names.ID = knownPlayers.Name WHERE IP = $ip");
                command.Parameters.AddWithValue("$ip", ipId);
                command.Connection = Connection;

                DbDataReader reader = await command.ExecuteReaderAsync();

                while (await reader.ReadAsync())
                {
                    string name = (string)reader["Name"];
                    ret.Add(name);
                }

                reader.Close();

                //connection.Close();

                ret.Sort();
            }

            Connection.Close();
            return ret;
        }
开发者ID:ChrisK91,项目名称:CWSRestart,代码行数:43,代码来源:KnownPlayers.cs


注:本文中的System.Data.SQLite.SQLiteCommand.ExecuteReaderAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。