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


C# SqlConnection.QueryDatatable方法代码示例

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


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

示例1: DeleteRegistration

        private async Task DeleteRegistration(SqlConnection conn)
        {
            // Capture the data from the database
            var registrationRecord = await conn.QueryDatatable(
                "SELECT * FROM PackageRegistrations WHERE id = @Id",
                new SqlParameter("@Id", Id));

            // Create a delete audit record
            var auditRecord = new PackageRegistrationAuditRecord(
                Id,
                registrationRecord,
                PackageRegistrationAuditAction.Deleted,
                Reason);

            await Console.WriteInfoLine(Strings.Package_DeleteCommand_WritingRegistrationAuditRecord, auditRecord.GetPath());
            if (!WhatIf)
            {
                await auditRecord.WriteAuditRecord("packageregistrations", StorageAccount);
            }

            // Delete all data
            var result = conn.Query(@"
                BEGIN TRAN

                DECLARE @actions TABLE(
                    TableName nvarchar(50),
                    Value nvarchar(MAX)
                )

                DELETE por 
                OUTPUT 'PackageOwnerRequests' AS TableName, u.Username AS Value INTO @actions
                FROM PackageOwnerRequests por 
                JOIN PackageRegistrations pr ON pr.[Key] = por.PackageRegistrationKey 
                JOIN Users u ON por.NewOwnerKey = u.[Key]
                WHERE pr.Id = @Id

                DELETE por 
                OUTPUT 'PackageRegistrationOwners' AS TableName, u.Username AS Value INTO @actions
                FROM PackageRegistrationOwners por 
                JOIN PackageRegistrations pr ON pr.[Key] = por.PackageRegistrationKey 
                JOIN Users u ON por.UserKey = u.[Key]
                WHERE pr.Id = @Id

                DELETE pr 
                OUTPUT 'PackageRegistrations' AS TableName, deleted.Id AS Value INTO @actions
                FROM PackageRegistrations pr 
                WHERE pr.Id = @Id

                SELECT * FROM @actions
                " + (WhatIf ? "ROLLBACK TRAN" : "COMMIT TRAN"), new
                {
                    Id = Id
                });
            await Console.WriteInfoLine(Strings.Package_DeleteCommand_DatabaseActions);
            await Console.WriteTable(result, d => new
            {
                Action = "DELETE",
                Table = (string)d.TableName,
                Value = (string)d.Value
            });
        }
开发者ID:NuGet,项目名称:NuGet.Operations,代码行数:61,代码来源:DeleteCommand.cs

示例2: DeleteUser

        private async Task DeleteUser(dynamic user, SqlConnection conn)
        {
            var userRecord = await conn.QueryDatatable(
                "SELECT * FROM [Users] WHERE [Key] = @key",
                new SqlParameter("@key", user.Key));

            var auditRecord = new UserAuditRecord(
                user.Username,
                user.EmailAddress ?? user.UnconfirmedEmailAddress + " (unconfirmed)",
                userRecord,
                UserAuditAction.Deleted,
                Reason);

            await Console.WriteInfoLine(Strings.User_WritingAuditRecord, auditRecord.GetPath());
            if (!WhatIf)
            {
                await auditRecord.WriteAuditRecord("user", StorageAccount);
            }

            await DeleteUserData(user, conn);

            await Console.WriteInfoLine(Strings.User_DeleteCommand_DeletionCompleted);
        }
开发者ID:NuGet,项目名称:NuGet.Operations,代码行数:23,代码来源:DeleteCommand.cs

示例3: DeletePackage

        private async Task DeletePackage(dynamic package, SqlConnection conn)
        {
            // Capture the data from the database
            var packageRecord = await conn.QueryDatatable(
                "SELECT * FROM Packages WHERE [Key] = @key",
                new SqlParameter("@key", package.Key));
            var registrationRecord = await conn.QueryDatatable(
                "SELECT * FROM PackageRegistrations WHERE [Key] = @key",
                new SqlParameter("@key", package.PackageRegistrationKey));

            // Create a delete audit record
            var auditRecord = new PackageAuditRecord(
                package.Id,
                package.Version,
                package.Hash,
                packageRecord,
                registrationRecord,
                PackageAuditAction.Deleted,
                Reason);

            await Console.WriteInfoLine(Strings.Package_DeleteCommand_WritingAuditRecord, auditRecord.GetPath());
            if (!WhatIf)
            {
                await auditRecord.WriteAuditRecord("package", StorageAccount);
            }

            await DeletePackageData(package, conn);

            await DeletePackageBlob(package);

            await Console.WriteInfoLine(Strings.Package_DeleteCommand_DeletionCompleted);
        }
开发者ID:NuGet,项目名称:NuGet.Operations,代码行数:32,代码来源:DeleteCommand.cs


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