hi,
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);
}
}
Thank you
greets niko