为什么小弟我用CodeSmith生成的代码,其他的都行,就这个出现这样的异常
为什么我用CodeSmith生成的代码,其他的都行,就这个出现这样的错误
private static IList<Restaurant> GetRestaurantsBySql( string safeSql )
{
List<Restaurant> list = new List<Restaurant>();
try
{
DataTable table = DBHelper.GetDataSet( safeSql );
foreach (DataRow row in table.Rows)
{
Restaurant restaurant = new Restaurant();
restaurant.Id = (int)row["Id"];
restaurant.ReName = (string)row["ReName"];
restaurant.RePhone = (string)row["RePhone"];
restaurant.ReFree = (decimal)row["ReFree"];
restaurant.OnTime = (string)row["OnTime"];
restaurant.ReAddress = (string)row["ReAddress"];
restaurant.ReParking = (int)row["ReParking"];
restaurant.ReUsing = (string)row["ReUsing"];
restaurant.ReSeries = (string)row["ReSeries"];
restaurant.ReLine = (string)row["ReLine"];
restaurant.Description = (string)row["Description"];
restaurant.ReMap = (string)row["ReMap"];
restaurant.Clicks = (int)row["Clicks"];
restaurant.Pic = (string)row["Pic"];
restaurant.ReType = ReTypeService.GetReTypeById((int)row["ReTypeId"]); //FK
restaurant.District = ReDistrictService.GetReDistrictById((int)row["DistrictId"]); //FK
restaurant.User = UserService.GetUserById((int)row["UserId"]); //FK
list.Add(restaurant);
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
指定的转换无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidCastException: 指定的转换无效。
源错误:
行 245: {
行 246: Console.WriteLine(e.Message);
行 247: throw e;
行 248: }
行 249:
------解决方案--------------------
友情 帮顶。
------解决方案--------------------
看看数据库字段有无null 检查数据类型
------解决方案--------------------
去掉try catch 看看哪一行出了问题
------解决方案--------------------
该回复于2010-02-23 09:43:40被版主删除
private static IList<Restaurant> GetRestaurantsBySql( string safeSql )
{
List<Restaurant> list = new List<Restaurant>();
try
{
DataTable table = DBHelper.GetDataSet( safeSql );
foreach (DataRow row in table.Rows)
{
Restaurant restaurant = new Restaurant();
restaurant.Id = (int)row["Id"];
restaurant.ReName = (string)row["ReName"];
restaurant.RePhone = (string)row["RePhone"];
restaurant.ReFree = (decimal)row["ReFree"];
restaurant.OnTime = (string)row["OnTime"];
restaurant.ReAddress = (string)row["ReAddress"];
restaurant.ReParking = (int)row["ReParking"];
restaurant.ReUsing = (string)row["ReUsing"];
restaurant.ReSeries = (string)row["ReSeries"];
restaurant.ReLine = (string)row["ReLine"];
restaurant.Description = (string)row["Description"];
restaurant.ReMap = (string)row["ReMap"];
restaurant.Clicks = (int)row["Clicks"];
restaurant.Pic = (string)row["Pic"];
restaurant.ReType = ReTypeService.GetReTypeById((int)row["ReTypeId"]); //FK
restaurant.District = ReDistrictService.GetReDistrictById((int)row["DistrictId"]); //FK
restaurant.User = UserService.GetUserById((int)row["UserId"]); //FK
list.Add(restaurant);
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
指定的转换无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidCastException: 指定的转换无效。
源错误:
行 245: {
行 246: Console.WriteLine(e.Message);
行 247: throw e;
行 248: }
行 249:
------解决方案--------------------
友情 帮顶。
------解决方案--------------------
看看数据库字段有无null 检查数据类型
------解决方案--------------------
去掉try catch 看看哪一行出了问题
------解决方案--------------------
该回复于2010-02-23 09:43:40被版主删除