asp.net项目出现 实例失败

zxg680 2009-10-18 07:44:26
错误:
实例失败
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.InvalidOperationException: 实例失败。

源错误:


行 164: {
行 165: Console.WriteLine(e.Message);
行 166: throw e;
行 167: }
行 168:


源文件: F:\Program Files\easyMule\Incoming\asp.net与extjs开发点卡在线销售系统\Y2毕业设计\项目源码\GameCardShop\GameCardShopDAL\Auto\CardTypeService.cs 行: 166
堆栈跟踪:

[InvalidOperationException: 实例失败。]
GameCardShop.DAL.CardTypeService.GetCardTypesBySql(String safeSql) in F:\Program Files\easyMule\Incoming\asp.net与extjs开发点卡在线销售系统\Y2毕业设计\项目源码\GameCardShop\GameCardShopDAL\Auto\CardTypeService.cs:166
GameCardShop.DAL.CardTypeService.GetAllCardTypes() in F:\Program Files\easyMule\Incoming\asp.net与extjs开发点卡在线销售系统\Y2毕业设计\项目源码\GameCardShop\GameCardShopDAL\Auto\CardTypeService.cs:102
GameCardShop.BLL.CardTypeManager.GetAllCardTypes() in F:\Program Files\easyMule\Incoming\asp.net与extjs开发点卡在线销售系统\Y2毕业设计\项目源码\GameCardShop\GameCardShopBLL\Auto\CardTypeManager.cs:37

[TargetInvocationException: 调用的目标发生了异常。]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +308
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +480
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1960
System.Web.UI.WebControls.BaseDataList.GetData() +57
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +284
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +56
System.Web.UI.WebControls.BaseDataList.DataBind() +52
System.Web.UI.WebControls.BaseDataList.EnsureDataBound() +76
System.Web.UI.WebControls.BaseDataList.CreateChildControls() +63
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +50
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041


源代码是
        private static IList<CardType> GetCardTypesBySql( string safeSql )
{
List<CardType> list = new List<CardType>();

try
{
147行------ DataTable table = DBHelper.GetDataSet( safeSql );

foreach (DataRow row in table.Rows)
{
CardType cardType = new CardType();

cardType.CardTypeId = (int)row["CardTypeId"];
cardType.CardTypeName = (string)row["CardTypeName"];
cardType.CardPrice = (int)row["CardPrice"];
cardType.CardImage = (string)row["CardImage"];

list.Add(cardType);
}

return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
166行--- throw e; }

}

我设置断点,发现只执行到147行,输出:
名称 值 类型
safesql "select * from CardType" String
table null System.Data.DataTable
list count=0

大家分析分析,给个意见,谢谢
...全文
159 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxg680 2009-10-18
  • 打赏
  • 举报
回复
谢谢 ♂风车车.Net ,a Rookie.,人生如梦的关注,问题已经解决了,原因是数据库连接方法DBHelper.GetDataSet()出问题了。导致数据库连不上查询不出数据。还是谢谢你们
zxg680 2009-10-18
  • 打赏
  • 举报
回复
谢谢以上各位帮忙,xray2005,wuyq11二位的代码我试了试不成功,主要是执行到147行
DataTable table = DBHelper.GetDataSet( safeSql ); 后,table是null,直接就异常了,foreach就没执行。 我想肯定是147行的错了,我再看看前面的。select * from CardType查询有数据4列30多行呢
wuyq11 2009-10-18
  • 打赏
  • 举报
回复
在查询分析器执行select * from CardType看看
wuyq11 2009-10-18
  • 打赏
  • 举报
回复
DataTable table = DBHelper.GetDataSet( safeSql );
foreach (DataRow row in table.Rows)
{
CardType cardType = new CardType();
cardType.CardTypeId = row["CardTypeId"]==DBNull.Value?0:(int)row["CardTypeId"];
cardType.CardTypeName =row["CardTypeName"]==DBNull.Value?"": (string)row["CardTypeName"];
cardType.CardPrice =row["CardPrice"]==DBNull.Value?0:(int)row["CardPrice"];
cardType.CardImage =row["CardImage"]== DBNull.Value?"":(string)row["CardImage"];
list.Add(cardType);
}
return list;
xierfly 2009-10-18
  • 打赏
  • 举报
回复
我设置断点,发现只执行到147行,输出:
名称 值 类型
safesql "select * from CardType" String
table null System.Data.DataTable
list count=0

=====
没有获取到值。在没有值的情况下 ,你foreach (DataRow row in table.Rows)可能出问题,先判断一下table的rowsv.count ,然后foreach
xray2005 2009-10-18
  • 打赏
  • 举报
回复
试试
xray2005 2009-10-18
  • 打赏
  • 举报
回复

foreach (DataRow row in table.Rows)
{
CardType cardType = new CardType();

cardType.CardTypeId =row["CardTypeId"]==null?-1: (int)row["CardTypeId"];
cardType.CardTypeName =row["CardTypeName"]==null?string.Empty: (string)row["CardTypeName"];
cardType.CardPrice =row["CardPrice"]==null?-1: (int)row["CardPrice"];
cardType.CardImage =row["CardImage"]==null?string.Empty: (string)row["CardImage"];

list.Add(cardType);
}

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧