views:

61

answers:

1

I have created a strongly typed dataset in the VS 2005 Dataset Designer. There are two tables that relates to each other in a one to many relationship: Claim and ClaimDetail. The designer automatically creates a function GetClaimDetailRows which returns all ClaimDetailRows for a ClaimRow. Why is this Array's length always 0? Because ClaimDetail contains more than 40 Million rows, i did'nt fill it before i call GetClaimDetailRows but had configured it's selectcommand that it takes a parameter idData to fill only the related records. But that seems not to work because the ClaimDetail-Datatable is empty.

alt text

The automaticaly generated function in the ClaimRow-Class which returns all related ClaimDetailRows:

        Public Function GetClaimDetailRows() As ClaimDetailRow()
            If (Me.Table.ChildRelations("Claim_ClaimDetail") Is Nothing) Then
                Return New ClaimDetailRow(-1) {}
            Else
                Return CType(MyBase.GetChildRows(Me.Table.ChildRelations("Claim_ClaimDetail")),ClaimDetailRow())
            End If
        End Function

When debugging i see that it jumps into the else block but returns 0 rows. Do i have to fill the Claimdetail-Datatable first(ClearBeforeFill=True) for each Claim? But then i dont need to use this function anymore.

UPDATE: I now fill the Datatable(ClearBeforeFill=True)before i call the Child-function and it works. But i dont understand why it could not throw an exception(optionally) when i try to acess a child-relation without having that datatable being filled(at least with 0 rows). Instead of that it returns 0 rows what can be correct or incorrect and is difficult to detect. Is this a lack of design or am i missing something?

+1  A: 

Because the generated GetChildRows() assumes (all) the child records are loaded into memory.

You'll have to write some code in the client part (Form). You can use the BindingSource.CurrentChanged and fill the appropriate records into the child table.

Henk Holterman
But that would burst the server's memory sooner or later when i leave all records in the datatable. Meanwhile i think i should use the GetData(idData) from the relation-table and iterate the returned Datatable instead of using this function.
Tim Schmelter
@Tim: That's what I was trying to say.
Henk Holterman
Thanks. I've updated my question.
Tim Schmelter
How could it throw an exception for 0 rows when that is also a valid state?
Henk Holterman
I'm not sure if i'm on the right track. Does a Datatable knows if it was filled from a DataAdapter or not? When yes, it could save this information in a flag and throws an exception if you access its Rows-Property or call a getChildRows Function which is related to this Datatable. Normally it doesnt make sense to get records from a Datatable that is not filled with records, make it?
Tim Schmelter
The DataTable is not aware of the Adapter.
Henk Holterman