本文介绍了C#TableAdapter删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i进入我的数据库,4个表,所有都是相互连接的。

在我的情况下我只是需要向你解释其中2个。



1.) - 用户表(PK = UserNumber)

2.) - Projekt表(PK = ProjektNumber)



如果用户存在并且Projekt已签署此用户,例如:



用户:1001有projekt号码:0001;



所以一切正常,但是,添加新用户我创建了一个新表单,我正在努力添加新表单用户。



但是如果我现在想要删除这个用户,那就不行了。它的工作我的意思是,但

它做错了。



我得到了一个referenze exeption,这是逻辑的,因为用户有Projekt数字补充说。所以我发现如果你想删除一个用户,你必须检查这个用户是否有projekt号码,如果他有,它应该首先删除projektnumbers然后删除用户。



我的程序现在可以工作,如果用户有Projekt号码它会删除用户,它只是告诉你有关参考文件。



- 我得到了这个代码成功实现了



为了把这些东西放到我的表单中,我使用了Databindings,我只是将

数据表拖放到我的表单中我自动得到一些菜单点,比如跳过前进/后退,添加新的和删除..等等。



但现在,如果用户有或没有projekt数字,它删除用户。



这里是按钮代码:





i have into my database, 4 Tables, all are connected to each other.
In my Situation i just Need to explain you 2 of them.

1.) - Users Table (PK = UserNumber)
2.) - Projekt Table (PK = ProjektNumber)

If an user exists and a Projekt is signed to this user, like this example:

user: 1001 has projekt number: 0001;

So everything works fine, BUT, to add new users i created a new form, wich is working to add new users.

But if i now want to delete this user, it aint work. It is working i mean, but
it did it wrong.

I got an referenze exeption, which was Logical, cause the user had Projekt numbers added. So i discovered that if you want to delete an user, you have to check if this user have projekt numbers, and if he has, it should delete first the projektnumbers and afterwards the user.

My Programm works now like, if an user has Projekt numbers it wount delete the user, it just tells you about the References.

- I got this code succesfully implemented

To get that stuff into my form, i used Databindings, i just drag and dropped the
datatable into my form and i got some menue Points automatically, like skip Forward/backwards, add new and delete..etc.

But now, it doesnt matter if an user has or hasnt projekt numbers, it deletes the user.

here is the button code:

private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
		{
			bool delete = true;
			
                        Data.lehrlingDataSet.NV_AUFKDataTable zeilen = 
                        AUFKAdapter.GetDataByKUNR(AktualKu);

			if (zeilen != null)
			{
			
			var zeile = zeilen.FirstOrDefault(a => a.KU_NR == AktualKu);
				if (zeile != null)
				{
					MessageBox.Show("This user has projekt NR");
					delete = false;
				}
			}
			if (delete == true)
			{
				this.Validate();
				this.nS_KUBindingSource.EndEdit();
			this.tableAdapterManager.UpdateAll(this.lehrlingDataSet);
			}
		}







谢谢



迎接niko




Thank you

greets niko

推荐答案


这篇关于C#TableAdapter删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 04:52