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


C# SQLiteCommand.ExecuteNonQueryAsync方法代码示例

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


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

示例1: AddPremiumPlayerAsync

        public async void AddPremiumPlayerAsync(string ip, Guid guid)
        {
            await Connection.OpenAsync();

            // Check if the player already has an entry
            SQLiteCommand command = new SQLiteCommand("SELECT COUNT(*) FROM premium WHERE GUID = $guid");
            command.Parameters.AddWithValue("$guid", guid.ToString("N"));

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

            if (count == 1)
            {
                command = new SQLiteCommand("UPDATE premium SET ip = $ip, timestamp = datetime('now') WHERE GUID = $guid");
                command.Parameters.AddWithValue("$guid", guid.ToString("N"));
                command.Parameters.AddWithValue("$ip", ip);
                command.Connection = Connection;
                await command.ExecuteNonQueryAsync();
            }
            else
            {
                command = new SQLiteCommand("INSERT INTO premium(IP, GUID) VALUES ($ip, $guid)");
                command.Parameters.AddWithValue("$guid", guid.ToString("N"));
                command.Parameters.AddWithValue("$ip", ip);
                command.Connection = Connection;
                await command.ExecuteNonQueryAsync();
            }

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

示例2: CreateTables

        public async Task CreateTables(SQLiteConnection connection)
        {
            using (
                var command =
                    new SQLiteCommand(
                        "CREATE TABLE `Playlists` (Name VARCHAR(255), Guid VARCHAR(36) NOT NULL, PRIMARY KEY (Guid))",
                        connection))
                await command.ExecuteNonQueryAsync();

            using (
                var command =
                    new SQLiteCommand(
                        "CREATE TABLE `PlaylistTracks` (PlaylistId VARCHAR(36), TrackId VARCHAR(36))",
                        connection))
                await command.ExecuteNonQueryAsync();

            using (
                var command =
                    new SQLiteCommand(
                        "INSERT INTO `Playlists` (Name, Guid) VALUES (@name, @guid)", connection))
            {
                command.Parameters.AddWithValue("@name", "Default Playlist");
                command.Parameters.AddGuid("@guid", Guid.NewGuid());

                await command.ExecuteNonQueryAsync();
            }
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:27,代码来源:PlaylistProvider.cs

示例3: CreateTables

 public Task CreateTables(SQLiteConnection connection)
 {
     using (
         var command =
             new SQLiteCommand("CREATE TABLE `Images` (Type INT, Guid VARCHAR(36) NOT NULL, Data VARCHAR(400), PRIMARY KEY (Guid))",
                 connection))
         return command.ExecuteNonQueryAsync();
 }
开发者ID:caesay,项目名称:Hurricane,代码行数:8,代码来源:ImagesProvider.cs

示例4: ExecuteQueryAsync

 public async Task ExecuteQueryAsync(string queryString)
 {
     _con.Open();
     _sqlCmd = _con.CreateCommand();
     _sqlCmd.CommandText = queryString;
     await _sqlCmd.ExecuteNonQueryAsync();
     //sql_con.Dispose();
     _con.Close();
 }
开发者ID:IlyaTsiamchyk,项目名称:Work,代码行数:9,代码来源:SQLiteContext.cs

示例5: CreateTables

 public Task CreateTables(SQLiteConnection connection)
 {
     using (
         var command =
             new SQLiteCommand(
                 "CREATE TABLE `Artists` (Name VARCHAR(255), MusicBrainzId VARCHAR(36), Url VARCHAR(255), Guid VARCHAR(36) NOT NULL, SmallImage VARCHAR(36), MediumImage VARCHAR(36), LargeImage VARCHAR(36), PRIMARY KEY (Guid))",
                 connection))
         return command.ExecuteNonQueryAsync();
 }
开发者ID:caesay,项目名称:Hurricane,代码行数:9,代码来源:ArtistProvider.cs

示例6: SetComplete

 public async void SetComplete(Todo todo)
 {
     using (var conn = new SQLiteConnection("Data Source=TodoList.s3db"))
     {
         using (var cmd = new SQLiteCommand("UPDATE TODOs SET Done = 1 WHERE Id = " + todo.Id, conn))
         {
             await conn.OpenAsync();
             await cmd.ExecuteNonQueryAsync();
         }
     }
 }
开发者ID:alwalker,项目名称:TodoList,代码行数:11,代码来源:TodoDAO.cs

示例7: DeleteDataAsync

        public async Task<int> DeleteDataAsync(InventurItem item)
        {
            //using (var db = new InventurContext())
            //{
            //    db.InventurItems.Attach(item);
            //    db.InventurItems.Remove(item);
            //    return await db.SaveChangesAsync();
            //}

            var command = new SQLiteCommand($"delete from {TABNAME} where ID={item.ID}", _dbTool.ConnectDb());
            return await command.ExecuteNonQueryAsync();
        }
开发者ID:mprattinger,项目名称:Inventur,代码行数:12,代码来源:DataService.cs

示例8: AddAlbum

        public Task AddAlbum(Album album)
        {
            Collection.Add(album.Guid, album);

            using (
                var command =
                    new SQLiteCommand(
                        "INSERT INTO `Albums` (Name, Guid, Artists) VALUES (@name, @guid, @artists)",
                        _connection))
            {
                command.Parameters.AddWithValue("@name", album.Name);
                command.Parameters.AddGuid("@guid", album.Guid);
                command.Parameters.AddWithValue("@artists",
                    string.Join(",", album.Artists.Select(x => x.Guid.ToString("D"))));

                return command.ExecuteNonQueryAsync();
            }
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:18,代码来源:AlbumsProvider.cs

示例9: ConvertToSqlite

 public async void ConvertToSqlite(string pathToExcelFile)
 {
     SetPathToParentDirectoryOfDatabaseFile();
     if (File.Exists(PathToDatabaseArchiveFile) && !File.Exists(_pathToDatabaseFile))
         ZipFile.ExtractToDirectory(PathToDatabaseArchiveFile, _pathToDatabase);
     using (
         var dbSqLiteConnection =
             new SQLiteConnection((WebConfigurationManager.ConnectionStrings["SQLite"].ConnectionString)))
     {                
         //load data from xlsx(excel) file
         var ds = await SetDataSet(pathToExcelFile);
         await dbSqLiteConnection.OpenAsync();
         //Set data from rows
         for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
         {
             var rowsStringBuilder = new StringBuilder();
             //load data from row to string
             for (var j = 0; j < ds.Tables[0].Rows[i].ItemArray.Length; j++)
             {
                 var row = string.IsNullOrEmpty(ds.Tables[0].Rows[i][j].ToString())
                     ? "NULL"
                     : ds.Tables[0].Rows[i][j].ToString();
                 if (j < ds.Tables[0].Rows[i].ItemArray.Length - 1)
                     rowsStringBuilder.Append(row + ",");
                 else
                     rowsStringBuilder.Append(row);
             }
             //Insert data into table
             var sqlQuery = "Insert into " + TableName + "(" + ColumnNames + ") Values(" + rowsStringBuilder + ");";
             using (var cmd = new SQLiteCommand(sqlQuery, dbSqLiteConnection))
                 await cmd.ExecuteNonQueryAsync();
         }
         dbSqLiteConnection.Shutdown();
         dbSqLiteConnection.Close();
     }
     if (File.Exists(PathToDatabaseArchiveFile))
         File.Delete(PathToDatabaseArchiveFile);
     ZipFile.CreateFromDirectory(_pathToDatabase, PathToDatabaseArchiveFile);
 }
开发者ID:marduk112,项目名称:excelconverter,代码行数:39,代码来源:ExcelConverter.cs

示例10: AddTodo

        public async void AddTodo(Todo todo)
        {
            using (var conn = new SQLiteConnection("Data Source=TodoList.s3db"))
            {
                var sb = new StringBuilder();
                sb.Append("INSERT INTO TODOs (Task, DueDate, CreateDate, Done) VALUES ('");
                sb.Append(todo.Task);
                sb.Append("', '");
                sb.Append(todo.DueDate.Value.ToString("yyyy-MM-dd HH:mm"));
                sb.Append("', '");
                sb.Append(todo.CreateDate.ToString("yyyy-MM-dd HH:mm"));
                sb.Append("', ");
                sb.Append(todo.Done ? 1 : 0);
                sb.Append(");");

                Debug.WriteLine("Executing: " + sb.ToString());

                using (var cmd = new SQLiteCommand(sb.ToString(), conn))
                {
                    await conn.OpenAsync();
                    await cmd.ExecuteNonQueryAsync();
                }
            }
        }
开发者ID:alwalker,项目名称:TodoList,代码行数:24,代码来源:TodoDAO.cs

示例11: AddTrack

        public Task AddTrack(PlayableBase track)
        {
            track.Guid = Guid.NewGuid();
            Collection.Add(track.Guid, track);
            Tracks.Add(track);
            _imageProvider.AddImage(track.Cover);

            using (
                var command =
                    new SQLiteCommand(
                        "INSERT INTO `Tracks` (Title, ArtistGuid, AlbumGuid, Guid, LastTimePlayed, MusicBrainzId, Duration, Cover, XmlData) VALUES (@title, @artistGuid, @albumGuid, @guid, @lastTimePlayed, @musicBrainzId, @duration, @cover, @xmlData)",
                        _connection))
            {
                command.Parameters.AddWithValue("@title", track.Title);
                command.Parameters.AddGuid("@artistGuid", track.Artist.Guid);
                command.Parameters.AddGuid("@albumGuid", track.Album?.Guid);
                command.Parameters.AddGuid("@guid", track.Guid);
                command.Parameters.AddWithValue("@lastTimePlayed", track.LastTimePlayed.ToString("yyyy-MM-dd HH:mm:ss"));
                command.Parameters.AddWithValue("@musicBrainzId", track.MusicBrainzId);
                command.Parameters.AddWithValue("@duration", XmlConvert.ToString(track.Duration));
                command.Parameters.AddGuid("@cover", track.Cover?.Guid);
                using (var stringWriter = new StringWriter())
                {
                    _serializer.Serialize(stringWriter, track);
                    command.Parameters.AddWithValue("@xmlData", stringWriter.ToString());
                }

                return command.ExecuteNonQueryAsync();
            }
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:30,代码来源:TrackProvider.cs

示例12: SetExportedAsync

        public async Task<bool> SetExportedAsync()
        {
            //using (var db = new InventurContext())
            //{
            //    await db.InventurItems.Where(x => x.Exported == false).ForEachAsync<InventurItem>(y => y.Exported = true);
            //    var changes = await db.SaveChangesAsync();
            //    if (changes > 0) return true;
            //    return false;
            //}

            var command = new SQLiteCommand($"update {TABNAME} set Exported=1 where Exported=0", _dbTool.ConnectDb());
            var changes =  await command.ExecuteNonQueryAsync();
            if (changes > 0) return true;
            return false;
        }
开发者ID:mprattinger,项目名称:Inventur,代码行数:15,代码来源:DataService.cs

示例13: UpdateLastTimePlayed

        public Task UpdateLastTimePlayed(PlayableBase track, DateTime newLastTimePlayed)
        {
            track.LastTimePlayed = newLastTimePlayed;
            using (var command = new SQLiteCommand("UPDATE `Tracks` SET [email protected] WHERE [email protected]", _connection))
            {
                command.Parameters.AddWithValue("@newLastTimePlayed", newLastTimePlayed.ToString("yyyy-MM-dd HH:mm:ss"));
                command.Parameters.AddGuid("@guid", track.Guid);

                return command.ExecuteNonQueryAsync();
            }
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:11,代码来源:TrackProvider.cs

示例14: UpdateAlbumArtists

        public Task UpdateAlbumArtists(Album album)
        {
            using (var command = new SQLiteCommand("UPDATE `Albums` SET [email protected] WHERE [email protected]", _connection))
            {
                command.Parameters.AddWithValue("@artists",
                    string.Join(",", album.Artists.Select(x => x.Guid.ToString("D"))));
                command.Parameters.AddGuid("@guid", album.Guid);

                return command.ExecuteNonQueryAsync();
            }
        }
开发者ID:caesay,项目名称:Hurricane,代码行数:11,代码来源:AlbumsProvider.cs

示例15: Update

        /// <summary>
        /// Edit an existing entry
        /// </summary>
        /// <param name="post"></param>
        /// <returns>a post object</returns>
        public async Task<Post> Update(Post post)
        {
            if (post == null)
            {
                return null;
            }

            bool result = false;

            try
            {

            using (var conn = new SQLiteConnection(Connectionstring))
            {
                conn.Open();
                string query = $"UPDATE {TableName} SET Title = '{post.Title}', Content = '{post.Content}' WHERE Id = {post.ID}";
                using (SQLiteCommand cmd = new SQLiteCommand(query, conn))
                {
                    await cmd.ExecuteNonQueryAsync();
                    result = true;
                }

                conn.Close();
            }
            }

            //useless catch, I need to handle it properly, either log or display a meaningfull message to the UI
            catch (SQLiteException ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return result ? post : null;
        }
开发者ID:mandiros3,项目名称:BlogNancy,代码行数:39,代码来源:DataBaseRepository.cs


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