C# Can';如果reader.ReadDataTable()不';t从数据库中的存储过程返回任何数据

C# Can';如果reader.ReadDataTable()不';t从数据库中的存储过程返回任何数据,c#,asp.net,.net,database,C#,Asp.net,.net,Database,我已经创建了一个名为GetCustomerPrivacyStatus的API,它正试图找出TandCstatus [HttpGet] [Route("GetCustomerPrivacyStatus")] public async Task<EULAInfo> GetCustomerPrivacyStatus() { var result = new EULAInfo(); string userObjectId = ClaimsPrincipa

我已经创建了一个名为
GetCustomerPrivacyStatus
的API,它正试图找出TandCstatus

[HttpGet]
[Route("GetCustomerPrivacyStatus")]
public async Task<EULAInfo> GetCustomerPrivacyStatus()
{
    var result = new EULAInfo();

    string userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
    var orgId = await GetOrgIdOfUser().ConfigureAwait(false);
    var TandCvalue = MasterDatabase.GetTermsAndConditionstatus(orgId).ToString();
    var TandCInt = TandCvalue != null ? TandCvalue : "0";
    var TandCstatus = Int16.Parse(TandCInt) == 0 ? false : true;
        
    result.status = TandCstatus;
        
    return result;
}
存储过程是:

CREATE PROCEDURE [dbo].[GetTermsAndConditionstatus]
    @orgId VARCHAR(100)
AS
    SELECT TermsAndConditionAccepted 
    FROM TermsAndConditionCheck 
    WHERE OrgId = @orgId
如果没有行,有没有办法将结果变量设置为null?

object result=null;
使用(var reader=newstoredProcedureReader(这个“GetTermsAndConditionstatus”,new{orgId}))
{
var dataTable=reader.ReadDataTable();
如果(dataTable.Rows.Count>0)
结果=数据表。行[0][“TermsAndConditionAccepted”];
}
返回结果;

这将解决您的问题

欢迎使用stackoverflow!不确定调用存储过程时,
StoredProcedureReader
执行什么操作。这可能有助于使用使用sql数据适配器@coder_b:StoredProcedureReader是一种读取存储在数据库中的存储过程在这种特定情况下,它调用GetTermsAndConditionstatus存储过程并将orgId作为参数传递。您可以检查的内容很少,orgId似乎是varchar,在您的sql中,看起来它被用作int类型,另一件事是如果OrgId是字符串,则需要用单引号括起来。最后,确保要传递的OrgId存在于TermsAndConditionCheck表行中。
CREATE PROCEDURE [dbo].[GetTermsAndConditionstatus]
    @orgId VARCHAR(100)
AS
    SELECT TermsAndConditionAccepted 
    FROM TermsAndConditionCheck 
    WHERE OrgId = @orgId