4
Answers

Related Tables

Photo of Carlos Sanchez

Carlos Sanchez

20y
1.7k
1
How to I know wether or not a record from a Table is related with others Tables. If the user want to delete a record from a teble and it's related with otrhers records I want to display a warning message, otherwise just delete it. What can I do. Thanking in advance. Carlos

Answers (4)

0
Photo of meenu_vij04
NA 5 0 20y
Hi csanchez if u want to create a relation between Customers & Orders Tables , you can do this: parentCol = ds.Tables["Customers"].Columns["Customer_ID"]; childCol = ds.Tables["Orders"].Columns["Customer_ID"]; // create a Relation called "CustOrder" DataRelation dr = new DataRelation("CustOrder", parentCol, childCol) // add a relation ds.Relations.Add(dr); now datarelation added in your dataset if u want to get a specific row, you can use SelectedIndex prop int x = listBox1.SelectedIndex; parentRow = ds.Tables["Customers"].Rows[x]; childRow = parentRow.GetChildRows(dr); foreach(DataRow drow in childRow) { Console.WriteLine(drow["Column1"]+" "+["Column2"].ToString()); } then u will get all the related records for that particular row. if u still have questions, then u can ask me. bye
0
Photo of Carlos Sanchez
NA 264 0 20y
Somebody knows about DataSet.Relations.Add() and GetChildRows()? How do they work? thanx.
0
Photo of Carlos Sanchez
NA 264 0 20y
What is a trigger? My questions are: For example: I have the next Data Base: *Customers* ---------------- ID_Customer Name Address TelephoneNum *Orders* ------------- ID_Order ID_Cliente Date - I want to create a relationship (Customers.ID_Customer = Orders.ID_Customer). How can I create it? - In my application the user can delete a customer, but I want to know wether or not the customer have orders, if the costumer have one or more orders I have to display a message: "Is not possible delete this Customer". How can I do it? Thanx Carlos
0
Photo of jinwolf
NA 176 0 20y
That's why you have relationships in a database. you can use a trigger.