小编Sar*_*gan的帖子

try catch的行为,最后是c#中的return语句工作流

我对这个尝试,捕获以及最后使用return语句工作流程毫无疑问......

此功能用于检索主管视图的员工休假信息.它工作得很好,但是如果找到if语句的数据,它将返回,否则块将返回.即使两者都获得了回报,它也会最终声明.我不知道为什么?

这里的代码片段:

List<Leave> ILeaveData.GetLeaveForSupervisorView(int userID)
{
    SqlConnection con = new SqlConnection(_connectionString);
    SqlCommand cmd = new SqlCommand("Storeprocedurename", con);
    cmd.CommandType = CommandType.StoredProcedure;

    cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int));
    cmd.Parameters["@Id"].Value = userID;

    // Get employee leave information

    try
    {
        con.Open();
        DataSet ds = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = cmd;
        adapter.Fill(ds);


        if (ds.Tables[0].Rows.Count > 0)
        {
            List<Leave> leave = new List<Leave>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                leave.Add(CreateLeaveForAdminViewFromDataRow(ds.Tables[0].Rows[i]));
            }
            return leave; // if data found then statement return …
Run Code Online (Sandbox Code Playgroud)

.net c# exception finally try-catch

2
推荐指数
1
解决办法
2198
查看次数

标签 统计

.net ×1

c# ×1

exception ×1

finally ×1

try-catch ×1