OK, two possible paths to follow here.
First, keeping with your untyped dataset, you are correct that the
drMaster = dsMaster.Tables("Master").NewRow() statement does not hook
that row to the datatable. To do that, you need to add
dsMaster.Tables("Master").Rows.Add(drMaster)
That hooks the row to the datatable. Thus, even if the row is blank, you
can load it with a key value programatically or via an identity column
or stored procedure. The row can then be accessed by identity, and
edited. You can then access the child rows (even though they are
non-existent at this point ;-) )
The other avenue, of which I am a fan, is to use strongly typed
datasets. These are basically regular datasets on steroids. When you
build the class, the class contains pre-defined functions that enable
you to get all child rows, find by primary key, etc. with a lot less
code and more clarity.
HTH
Jeff Little
CounselTech LLC
-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED]] On Behalf Of Zafar Iqbal
Sent: Thursday, August 08, 2002 3:36 PM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Master/Detail Help
Hi All !
I have a little problem, I have a dataset which contains three tables.
One is master and other two are its details.
I have created a class which is as follows
Public Class TestMaster
Private dsMaster as DataSet
Public drMaster as DataRow
Public dvDetail as DataView
Public Function LoadMaster(vMasterID as Integer) As Boolean
Dim drvTemp as DataRowView
Dim i as integer
Dim dvTemp as DataView
drMaster = dsMaster.Tables("Master").Rows.Find(vMasterID)
dvTemp = dsMaster.Tables("Master").DefaultView
i = dvTemp.Find(vMasterID)
drvTemp = dvTemp(i)
dvDetail = drvTemp.CreateChildView("MasterDetails")
End Function
Public Function NewMaster()
Dim drvTemp as DataRowView
Dim i as integer
Dim dvTemp as DataView
drMaster = dsMaster.Tables("Master").NewRow()
'Here I need to get the child view of this master row
'I could not solve that problem
'can any body solve it for me or guide me how to hande this
solution
'dvDetail = drvTemp.CreateChildView("MasterDetails")
End Function
End Class
The dataset contains two tables tblMaster and tblDetails having
relationship named MasterDetails
Problem is that when we retrieve the existing records we can retrieve
the child rows as a view, which helps in displaying in a grid and adding
new rows, modify them and others. But when we create a new row, it is
not attached to the table yet, so we can not get it in master table's
default view, and we can not access the child rows at this moment, of
course they don't exist. but we need to provide that view to the front
end user, so that it can use that view as he was using the detail rows'
view when he asked for the existing master rows. I could not find a
solution for that kind of problem. If any one can guide me on it, that
would be great favor to me.
Someone said that when you create a new row with this method, the row
exists in the datatable, here is his comments:
=============== Ian Griffiths
You said that when you create a new row it's not attached to the table.
How can that be? Here's your code:
> > drMaster = dsMaster.Tables("Master").NewRow()
That looks to me like it should add a new row to the Master table. Have
you tried printing out drMaster.Table.TableName in the debugger - it
should say Master. Try it. If it does, I think you may be
misdiagnosing the problem. If it doesn't please say what it does.
What I want to know (and what I think anyone else trying to answer your
question will want to know, which is why I suggest that you put this
information in your post) is what happens when you uncomment this line:
> > 'dvDetail = drvTemp.CreateChildView("MasterDetails")
Why is it commented out? What happens when you try this?
One thing that occurs to me - have you tried calling AcceptChanges on
either the DataTable or the DataSet? I'm wondering if you have to do
this before you can create a child view.
=============== Ian Griffiths
Regards
Zafar Iqbal
You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.