奇怪:枪毙dataset中的一个表时,它挂出免死金牌,气得我直吐血...哪位军事指点一下?谢谢万恶的.NET错误提示:“/xxx”应用程序中的服务器错误。
---------------------------------------------------------------------约束“CategoryRelation”不属于此 DataTable。 说我的下面这行代码错, 注释掉这行下面哪行又出错。
ds.Tables["currentCategory"].Constraints.Remove("CategoryRelation");当然如果用上这行可以消除错误,但感觉未找到病根。
ds.EnforceConstraints=false;
源码如下:
----------------------------------------------------------------------
Category category = new Category(); DataSet ds = new DataSet();
SqlDataAdapter da = category.GetSubList( m_categoryId , m_type ); if(da!=null)
{
da.Fill(ds,"subCategory"); da = category.GetCurrentList( m_categoryId , m_type );
da.Fill(ds,"currentCategory"); ds.Relations.Add("CategoryRelation",
ds.Tables["currentCategory"].Columns["categoryId"],
ds.Tables["subCategory"].Columns["ParentCategoryId"]); repLeftCategory.DataSource = ds.Tables["currentCategory"];
repLeftCategory.DataBind();
//ds.EnforceConstraints=false;
ds.Relations.Remove("CategoryRelation"); ds.Tables["currentCategory"].Constraints.Remove("CategoryRelation");
ds.Tables.Remove("currentCategory");
}
---------------------------------------------------------------------约束“CategoryRelation”不属于此 DataTable。 说我的下面这行代码错, 注释掉这行下面哪行又出错。
ds.Tables["currentCategory"].Constraints.Remove("CategoryRelation");当然如果用上这行可以消除错误,但感觉未找到病根。
ds.EnforceConstraints=false;
源码如下:
----------------------------------------------------------------------
Category category = new Category(); DataSet ds = new DataSet();
SqlDataAdapter da = category.GetSubList( m_categoryId , m_type ); if(da!=null)
{
da.Fill(ds,"subCategory"); da = category.GetCurrentList( m_categoryId , m_type );
da.Fill(ds,"currentCategory"); ds.Relations.Add("CategoryRelation",
ds.Tables["currentCategory"].Columns["categoryId"],
ds.Tables["subCategory"].Columns["ParentCategoryId"]); repLeftCategory.DataSource = ds.Tables["currentCategory"];
repLeftCategory.DataBind();
//ds.EnforceConstraints=false;
ds.Relations.Remove("CategoryRelation"); ds.Tables["currentCategory"].Constraints.Remove("CategoryRelation");
ds.Tables.Remove("currentCategory");
}
解决方案 »
- MVC设计问题
- 我的网站用的三层结构,业务逻辑都做好了,感觉不到使用ObjectDatasource意义,您们用他吗?
- 有关ajax的问题(在updatePanel中动态添加控件的问题)
- 如何给table统一赋值
- 自定义IHttpHandler类.并发冲突总么办
- @Page Transaction="Required"导致的错误
- asp.net Cookie问题,这个小甜饼还真是可爱啊
- asp.net中上传了一个网页,但是在调试过程中无法显示出现:HTTP 错误 400 - Bad Request。
- 请问怎么调用页面上WebUserControl的方法
- 使用Directory.Move为目录改名后,Session总是丢失,为什么会这样,如何解决?
- 有谁用过硕思魔法菜单没有?怎样加入到ASP.NET的网页中?在线等!
- 点击datagrid中的一行,如何将该行中某一列的内容取出并显示在textbox中??
这一句代码有问题:
因为Constraints.Remove("CategoryRelation");是删除指定的表,这里是
CategoryRelation表,但CategoryRelation是你先前建的关系,此关系也删除
所以这里直接改成
ds.Tables.Remove("subCategory");
然后在删除
ds.Tables.Remove("currentCategory");
就可以了
问一下Category category = new Category();
是在什么东西
tks