Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 错误CS0161';RateController.GetRateById(长)和#x27;:并非所有代码路径都返回值_C#_Asp.net Mvc - Fatal编程技术网

C# 错误CS0161';RateController.GetRateById(长)和#x27;:并非所有代码路径都返回值

C# 错误CS0161';RateController.GetRateById(长)和#x27;:并非所有代码路径都返回值,c#,asp.net-mvc,C#,Asp.net Mvc,我有个错误 严重性代码描述项目文件行抑制状态错误CS0161“RateController.GetRateById(long)”:并非所有代码路径都返回值shenoywebapi D:\shenoystudio\shenoywebapi\Controllers\RateController.cs 192 Active [Route("api/rate/getrate/{id}")] public Rate GetRateById(long id) {

我有个错误

严重性代码描述项目文件行抑制状态错误CS0161“RateController.GetRateById(long)”:并非所有代码路径都返回值shenoywebapi D:\shenoystudio\shenoywebapi\Controllers\RateController.cs 192 Active

       [Route("api/rate/getrate/{id}")]
       public Rate GetRateById(long id)
       {
           var result = new Rate();

           var dsRate = SqlHelper.ExecuteDataset(AppDatabaseConnection, CommandType.StoredProcedure, 0, "GetRateById", new SqlParameter("@Id", id));

           if (dsRate.Tables[0].Rows.Count > 0)
           {
               DataRow row = dsRate.Tables[0].Rows[0];
               result = new Rate
               {
                   Id = Convert.ToInt64(row[0]),
                   wefDate = Convert.ToDateTime(row[1]),
                   //ProductRates =new List<ProductRate>() { new ProductRate() { Rate = Convert.ToInt64(row[2])} }
               };

           }
           var ProductRatesList = new List<ProductRate>();
           var dsRateDetails = SqlHelper.ExecuteDataset(AppDatabaseConnection, CommandType.StoredProcedure, 0, "GetRateDetailsById", new SqlParameter("@RateId", id));

           if (dsRateDetails.Tables[0].Rows.Count > 0)
           {
               foreach (DataRow row in dsRateDetails.Tables[0].Rows)
               {
                   ProductRatesList.Add(new ProductRate
                   {
                       Rate = Convert.ToDecimal(row[0])
                   });
               }
               result.ProductRates = ProductRatesList;
               return result;
           }
       }

只有在这一部分,您才有返回语句:

if (dsRateDetails.Tables[0].Rows.Count > 0)
       {
           foreach (DataRow row in dsRateDetails.Tables[0].Rows)
           {
               ProductRatesList.Add(new ProductRate
               {
                   Rate = Convert.ToDecimal(row[0])
               });
           }
           result.ProductRates = ProductRatesList;
           return result;
       }
如果代码没有转到这个if语句,则没有return语句

if (dsRateDetails.Tables[0].Rows.Count > 0)
您应该在方法的最后一个大括号之前添加:

return result;
GetRateById()需要返回一个速率。移动
返回结果向下一行,超出
if
语句可能重复的
if (dsRateDetails.Tables[0].Rows.Count > 0)
return result;