C# Throw 报错,请指教
请问各位大侠,这段代码中的Throw 为什么报错 ,删除也提示说没有返回值:
public static Article GetArticleByArticleId(int id)
{
string sql = "select * from article where articleId=@articleId";
try
{
using (SqlDataReader reader = SqlHelper.GetReader(sql, new SqlParameter("@articleId", id)))
{
if (reader.Read())
{
return FillRecord(reader);
}
else
{
return null;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
------解决方案--------------------
你的这个方法中 private static Article FillRecord(SqlDataReader reader)
把赋值的地方都加上判断
C# code
if(reader["articleId"]!=DBNull.value)
{
a.ArticleId = Convert.ToInt32(reader["articleId"]);
}//其它的自己加上