ASP.NET dataset getdataBy Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign key constraints

爱⌒轻易说出口 提交于 2019-12-13 16:16:22

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/6014365/asp-net-dataset-getdataby-failed-to-enable-constraints-one-or-more-rows-contain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!