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


C# SqlCommand.ExecuteReaderExtAsync方法代码示例

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


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

示例1: RefreshAsync

        public static async Task<DisplayData> RefreshAsync(int displayId)
        {
            DisplayData data = new DisplayData()
            {
                DisplayId = 0,
                IdleInterval = 0,
                Hash = 0,
                RecycleTime = null
            };
            
            using (SqlCommand cmd = new SqlCommand("sp_GetDisplayData"))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@displayId", displayId);

                await cmd.ExecuteReaderExtAsync((reader) =>
                {
                    data.DisplayId = reader.IntOrZero("DisplayId");
                    data.IdleInterval = reader.IntOrZero("IdleInterval");
                    data.Hash = reader.IntOrZero("Hash");

                    if (reader["RecycleTime"] != DBNull.Value)
                    {
                        data.RecycleTime = (TimeSpan)reader["RecycleTime"];
                    }

                    return false;
                });
            }
            
            return data;
        }
开发者ID:fuel9,项目名称:DisplayMonkey,代码行数:32,代码来源:Display.cs

示例2: GetDataAsync

        public static async Task<Content> GetDataAsync(int contentId)
        {
            Content content = null;

            using (SqlCommand cmd = new SqlCommand() 
            {
                CommandType = CommandType.Text,
                CommandText = "SELECT TOP 1 * FROM Content WHERE [email protected]",
            })
            {
                cmd.Parameters.AddWithValue("@contentId", contentId);
                await cmd.ExecuteReaderExtAsync((reader) =>
                {
                    content = new Content()
                    {
                        ContentId = reader.IntOrZero("ContentId"),
                        Name = reader.StringOrBlank("Name"),
                        Type = reader.ValueOrDefault<ContentTypes>("Type", ContentTypes.ContentType_Picture),
                        Data = reader.BytesOrNull("Data"),
                    };
                    return false;
                });
            }

            return content;
        }
开发者ID:fuel9,项目名称:DisplayMonkey,代码行数:26,代码来源:Content.cs

示例3: GetNextFrameAsync

        public static async Task<Frame> GetNextFrameAsync(int panelId, int displayId, int previousFrameId)
		{
            Frame nci = new Frame()
            {
                PanelId = panelId,
                DisplayId = displayId
            };

            using (SqlCommand cmd = new SqlCommand("sp_GetNextFrame"))
            {
				cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@panelId", SqlDbType.Int).Value = panelId;
                cmd.Parameters.Add("@displayId", SqlDbType.Int).Value = displayId;
                cmd.Parameters.Add("@lastFrameId", SqlDbType.Int).Value = previousFrameId;

                await cmd.ExecuteReaderExtAsync((dr) =>
                {
                    nci._initfromRow(dr);
                    return false;
                });
            }

            if (nci.FrameId > 0)
            {
                switch (nci.FrameType)
                {
                    case FrameTypes.Clock:
                        nci = new Clock(nci);
                        break;

                    case FrameTypes.Html:
                        nci = new Html(nci);
                        break;

                    case FrameTypes.Memo:
                        nci = new Memo(nci);
                        break;

                    //case FrameTypes.News:

                    case FrameTypes.Outlook:
                        nci = new Outlook(nci);
                        break;

                    case FrameTypes.Picture:
                        nci = new Picture(nci);
                        break;

                    case FrameTypes.Powerbi:
                        nci = new Powerbi(nci);
                        break;

                    case FrameTypes.Report:
                        nci = new Report(nci);
                        break;

                    case FrameTypes.Video:
                        nci = new Video(nci);
                        break;

                    case FrameTypes.Weather:
                        nci = new Weather(nci);
                        break;

                    case FrameTypes.YouTube:
                        nci = new YouTube(nci);
                        break;

                    default:
                        break;
                }
            }

            return nci;
		}
开发者ID:fuel9,项目名称:DisplayMonkey,代码行数:75,代码来源:Frame.cs

示例4: GetAccessTokenAsync

        public static async Task<string> GetAccessTokenAsync(int accountId)
        {
            string accessToken = null;

            await DataAccess.ExecuteTransactionAsync(async (cnn, trn) => {
                using (SqlCommand cmd = new SqlCommand()
                {
                    CommandType = CommandType.Text,
                    CommandText = "select top 1 * from AzureAccount with(updlock,rowlock) where [email protected]",
                    Connection = cnn,
                    Transaction = trn,
                })
                {
                    cmd.Parameters.AddWithValue("@accountId", accountId);

                    DateTime? expiresOn = null;
                    string clientId = null, clientSecret = null, user = null, password = null, tenantId = null;
                    Models.AzureResources resource = Models.AzureResources.AzureResource_PowerBi;
                    await cmd.ExecuteReaderExtAsync((reader) =>
                    {
                        expiresOn = reader.AsNullable<DateTime>("ExpiresOn");
                        accessToken = reader.StringOrBlank("AccessToken").Trim();
                        resource = reader.ValueOrDefault<Models.AzureResources>("Resource", Models.AzureResources.AzureResource_PowerBi);
                        clientId = reader.StringOrBlank("ClientId");
                        clientSecret = reader.StringOrBlank("ClientSecret");
                        user = reader.StringOrBlank("User");
                        password = RsaUtil.Decrypt(reader.BytesOrNull("Password"));
                        tenantId = reader.StringOrDefault("TenantId", null);
                        return false;
                    });

                    if (string.IsNullOrWhiteSpace(accessToken) || !expiresOn.HasValue || expiresOn.Value < DateTime.UtcNow)
                    {
                        TokenInfo token = await Token.GetGrantTypePasswordAsync(
                            resource,
                            clientId,
                            clientSecret,
                            user,
                            password,
                            tenantId
                            );
                        using (SqlCommand cmdu = new SqlCommand()
                        {
                            CommandType = CommandType.Text,
                            CommandText = "update AzureAccount set [email protected], [email protected] where [email protected]",
                            Connection = cnn,
                            Transaction = trn,
                        })
                        {
                            cmdu.Parameters.AddWithValue("@accountId", accountId);
                            cmdu.Parameters.AddWithValue("@accessToken", token.AccessToken);
                            cmdu.Parameters.AddWithValue("@expiresOn", token.ExpiresOn.AddMinutes(-1)); // allow 1 minute to avoid issues
                            cmdu.ExecuteNonQuery();
                        }
                        accessToken = token.AccessToken;
                    }
                }
            });

            return accessToken;
        }
开发者ID:fuel9,项目名称:DisplayMonkey,代码行数:61,代码来源:Powerbi.cs


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