ASP.NET数据getdataBy未能启用约束。一行或多行中包含违反非空,唯一,或外键约束 [英] ASP.NET dataset getdataBy Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign key constraints

查看:236
本文介绍了ASP.NET数据getdataBy未能启用约束。一行或多行中包含违反非空,唯一,或外键约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个非常简单的Web窗体
我有一个按钮,这种形式在GridView和包含链接的表账单的数据集,文案,docket_bill等。

在按钮点击我用下面的code

 保护无效button_click(对象发件人,EventArgs的发送)
{
billTableAdapter Billta =新billTableAdapter();
gridview1.datasource = Billta.getTop20Bills();
gridview1.databind()'
}

现在,当我按一下按钮,我得到以下错误


  

未能启用约束。一个或
  多行中包含违反
  非空,唯一或外键
  约束


然而,当我改变code到

 保护无效button_click(对象发件人,EventArgs的发送)
    {
    billTableAdapter Billta =新billTableAdapter();
    gridview1.datasource = Billta.getdata();
    gridview1.databind()'
    }

它工作正常。 billTa.getData()从数据集中获取所有行和GridView中显示出来。但是当我添加查询并仅选择几列,那么它给了我前面提到的错误。

任何想法,这里是错的?

为的getData SQL脚本()=选择法案* 搜索

 为getTop20Bills SQL脚本=选择前20 bill_id,从比尔bill_amount


解决方案

我猜你在billTableAdapter有超过两列。在getTop20Bills()选择只有两个,你需要列。你必须缺少的列添加到您的第二个脚本。或者,您可以创建新表适配器,只包含这两列和绑定网格视图以新的适配器

hi i have a very simple webform i have a button and a gridview on this form and a dataset that contains linked tables bill, docket, docket_bill etc.

On Button click i use the following code

  protected void button_click(object sender, EventArgs e)
{
billTableAdapter Billta = new billTableAdapter();
gridview1.datasource = Billta.getTop20Bills();
gridview1.databind()'
}

Now when i click on the button, i get the following error

"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign key constraints"

However, when i change the code to

 protected void button_click(object sender, EventArgs e)
    {
    billTableAdapter Billta = new billTableAdapter();
    gridview1.datasource = Billta.getdata();
    gridview1.databind()'
    }

It works fine. billTa.getData() gets all the rows from the dataset and shows up in the gridview. but when i add a query and select only few columns, then it gives me the aforementioned error.

Any idea what is wrong here?

SQL Scripts for getdata() = select * from bill

SQL script for getTop20Bills = select top 20 bill_id, bill_amount from bill

解决方案

I guess you have more than two columns in your billTableAdapter. In getTop20Bills() you select only two columns you need. You have to add missing columns to your second script. Or you can create new Table Adapter, that contains only this two columns and bind grid view to new adapter

这篇关于ASP.NET数据getdataBy未能启用约束。一行或多行中包含违反非空,唯一,或外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆