Dataset.Relations

  • Thread starter Thread starter gjnave
  • Start date Start date
G

gjnave

Guest
I have racked my brains for the ENTIRE day trying to figure out how I can delete a single row from within a child table.

This is my dataset structure:
Organization
Country
City
Ministry
Worker

Say that the Organization Table has One Entry, but the Country table has 3 entries (lets say Korea, USA, France) . And lets say that the City table has 3 entries under each of the 3 countries. (A total of 9 cities, which dont show together because they are related to different countries in the country table - or underneath different rows of the Country Table).

Now, i want to delete the city of Denver (which is underneath the USA entry in the Country table). So i navigate to the correct relation and tell it which row to delete (in this case row #2) --
**CODE**
dataset1.tables("country_city").rows(2).delete
**End of Code**

But aha! It didnt delete what I thought it should. Looking at the Datagrid, the row I want to delete being the 3rd down, you would think that that would be row #2.
But what is really happening is that by telling the progam to go to "country_city" , Im not just getting the cities for the USA, but for all the other countries also. So the index is not just for USA but for all the countries.

SO heres the question. How can I tell the program to not include everything beneath all the rows in the Country table, but to only include whats beneath a specific row in the Table (Namely Denver)?


Thank You
 
Using a Dataview, try this...
If you are using another method, let me know.
Code:
Dim strCurrentCountryID As String = DataViewCountry(DataGridCountry.CurrentRowIndex)("ID").ToString
DataViewCity.RowFilter = "ID = " & strCurrentCountryID

With DataGridCity
      .DataSource = DataViewCity
End With
 
This is the line of code that I am working with... i found that if I preknow the row of the ParentTable that i can get the childrows for it and delete the approriate row (see below).
**
dataR = ds1.tables(parentTable).Rows.item(1).getChildRows(relationName).getValue(datagrid1.currentCell.RowNumber)

datar.delete
**
However, in the realworld i wont preknow the Parents Row Number. I can get the Parent tables Row NAME, but not the index. Here is the code that I used.

**
parentRowName = ds1.Tables(tableName).Rows.Item(DataGrid1.CurrentCell.RowNumber).GetParentRow(relationName).Item(0)
**

Any ideas on how to get the index number?
 
This should get the Index...

Code:
if you declare a Dataview, you can do this...
Dim strCurrentCountryID As String = DataViewCountry(DataGridCountry.CurrentRowIndex)("ID").ToString
 
Back
Top