Hi,
I have an issue involving retrieving a set of child rows in a dataset.
I have populated a dataset with three tables Categories, Projects and Tasks. In the dataset relations I have set up a relationship between Categories and Projects and between Projects and Tasks.
Private Sub Defaults_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
....
with myDset
.tables(0).TableName ="Categories"
.tables(0).Columns("CategoryID").Unique = True
.tables(1).TableName ="Projects"
.tables(1).Columns("ProjectCode").Unique = True
.tables(2).TableName ="Tasks"
.tables(2).Columns("TaskCode").Unique = True
with .relations
.Add("ProjectCategory", myDSet.Tables("Categories").Columns("CategoryID"), myDSet.Tables("Projects").Columns("CategoryID"))
.Add("ProjectTasks", myDSet.Tables("Projects").Columns("ProjectCode"), myDSet.Tables("Tasks").Columns("ProjectCode"))
end with
end with
.....
end sub
This all works fine when I debug.
Using this dataset I wish to populate some comboboxes to allow the user to select a Category then a Project and get the list of
tasks in a listbox.
So I populate the category combo with no issue. However when I try and retrieve the selected row of the table I get an error stating that no primary key has been set.
Private Sub cbProjCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbProjCat.SelectedIndexChanged
....
dim Category as Dataitem 'custom class allows an id and string value to be passed into combobox
'Which Category has been selected
Category = cbProjCat.SelectedItem
'What is the ID?
CategoryID = Category.ID
'Get this row in the Categories table in the Dataset
CategoryRow = myDSet.Tables("Categories").Rows.Find(CategoryID)
...
end sub
I tried setting the primarykey on the datatables like so but I get an error about it not accepting 1 dimensional arrays...
myDset.Tables("Categories").PrimaryKey = myDset.Tables("Categories").Columns("CategoryID")
Anyone out there have any ideas?
Do I need to set the Primarykey?
Does the primary key need to be composite i.e. two columns?
Thanks in advance