SqlHelperExecuteScalarAsyncT(String) Method

異步執行指令並取得第1筆資料的第1個欄位值

Definition

Namespace: eBizprise.Framework
Assembly: eBizprise.Framework.Database.SqlHelper (in eBizprise.Framework.Database.SqlHelper.dll) Version: 25.0.3.0+6e92afb880fa099fdfe407c9aa8d1b17eaaf3625
C#
public Task<DatabaseResult<T>> ExecuteScalarAsync<T>(
	string statement
)

Parameters

statement  String
查詢指令

Type Parameters

T

Return Value

TaskDatabaseResultT
DatabaseResult<T>

Example

C#
using (SqlHelper sqlHelper = new SqlHelper("SqlServer"))
{
    DatabaseResult<Guid> result = sqlHelper.ExecuteScalar<Guid>(sqlHelper.GetQueryString<Employee>() + " Where IneffectiveDate Is Null Or IneffectiveDate >= GetDate()");

    if (result.IsSuccess) {
        Guid employeeId = result.Result;

        //Do something
    } else {
        Exception exception = result.Exception;

        //Error handling
    }
}

Revision History

DateVersionDescription
2020/09/281.0.21.0增加異步處理機制
2025/09/1925.0.0.0彙整2025年度初版

See Also