本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}