|
 |
aspx thread: creation of Hierarchial Recordsets
Message #1 by NK Ramanathan <nkram2000@y...> on Wed, 21 Mar 2001 03:24:32 -0800 (PST)
|
|
Hi there,
I am facing problems in creating hiereachial
recordsets using ado.net and how to retrieve the
hierarchial recordset.
Can anybody suggest that whether there is any command
like "Shape" of ADO 2.0 which creates a hierarchial
recordsets.
I am doing it in this way.
qry = "select * from employee"
dsCmd.SelectCommand() = New ADO.ADOCommand(qry,
adc)
dscmd.FillDataSet(dset, ptable)
dtable = dset.Tables(0)
qry = "select * from dept"
dsCmd.SelectCommand() = New ADO.ADOCommand(qry,
adc)
dscmd.FillDataSet(dset, ptable)
dtable1 = dset.tables(1)
childCol
dset.Tables("emp").Columns("deptid")
parentCol
dset.Tables("dept").Columns("deptid")
' Create DataRelation.
reldeptid = New DataRelation("reldeptid",
parentCol, childCol)
' Add the relation to the DataSet.
dset.Relations.Add(reldeptid)
if this is the correct way then how to retrieve the
records from the child tables?
Thx in advance
Ramanathan
Message #2 by "Dave Sussman" <davids@i...> on Thu, 22 Mar 2001 10:02:06 -0000
|
|
Yep, that's pretty much the way to do it. You can remove some code too, by
leaving out a few variables:
myCommand = New ADODataSetCommand("Select * from publishers",
myConnection)
myCommand.FillDataSet(ds, "Publishers")
myCommand = New ADODataSetCommand("Select * from titles", myConnection)
myCommand.FillDataSet(ds, "titles")
rel = New DataRelation("PublishersTitles", _
ds.Tables("Publishers").Columns("pub_id"), _
ds.Tables("Titles").Columns("pub_id"))
ds.Relations.Add(rel)
Otherwise that's the expected way. Extracting rows depends on what you are
doing. You can use the DataRow object to enumerate through the rows, and
then the GetChildRows method of the data row to get the child rows for the
selected parent row. This can also be done in databinding like so:
Publishers.DataSource = ds.Tables("Publishers").DefaultView
Publishers.DataBind()
<asp:Repeater id="Publishers" runat="server">
<template name="ItemTemplate">
<asp:DataList id="Pictures" border="0"
RepeatDirection="vertical" RepeatColumns="1"
DataSource ='<%# CType(Container.DataItem,
DataRowView).CreateChildView("PublishersTitles") %>'
runat="server">
When binding you use a DataRowView rather than a DataRow, and the
CreateChildView just extracts the child rows and creates a view from it.
Dave
"NK Ramanathan" <nkram2000@y...> wrote in message news:49607@a...
>
> Hi there,
> I am facing problems in creating hiereachial
> recordsets using ado.net and how to retrieve the
> hierarchial recordset.
> Can anybody suggest that whether there is any command
> like "Shape" of ADO 2.0 which creates a hierarchial
> recordsets.
>
> I am doing it in this way.
>
> qry = "select * from employee"
>
> dsCmd.SelectCommand() = New ADO.ADOCommand(qry,
> adc)
> dscmd.FillDataSet(dset, ptable)
> dtable = dset.Tables(0)
>
> qry = "select * from dept"
>
> dsCmd.SelectCommand() = New ADO.ADOCommand(qry,
> adc)
> dscmd.FillDataSet(dset, ptable)
> dtable1 = dset.tables(1)
>
> childCol
> dset.Tables("emp").Columns("deptid")
> parentCol
> dset.Tables("dept").Columns("deptid")
> ' Create DataRelation.
> reldeptid = New DataRelation("reldeptid",
> parentCol, childCol)
> ' Add the relation to the DataSet.
> dset.Relations.Add(reldeptid)
>
> if this is the correct way then how to retrieve the
> records from the child tables?
>
>
> Thx in advance
> Ramanathan
>
>
>
Message #3 by NK Ramanathan <nkram2000@y...> on Sun, 25 Mar 2001 22:06:48 -0800 (PST)
|
|
Thx Dave,
But I have a problem in updating the hierarchical
recorset in ado.net, i am able to create hierarchical
record set, but after making the changes if i try to
update it is not updating.I have written this code
myCommand = New ADODataSetCommand("Select * from
publishers",myConnection)
myCommand.FillDataSet(ds, "Publishers")
myCommand = New ADODataSetCommand("Select * from
titles", myConnection)
myCommand.FillDataSet(ds, "titles")
rel = New DataRelation("PublishersTitles", _
ds.Tables("Publishers").Columns("pub_id"), _
ds.Tables("Titles").Columns("pub_id"))
ds.Relations.Add(rel)
after making changes i have written this code
myCommand.TableMappings.Add("Publishers",
"Publishers")
myCommand.TableMappings.Add("Titles", "Titles")
myCommand.Update(ds, "Publishers")
myCommand.Update(ds, "Titles")
This is not giving error but not updating the
database.
I am doing all the changes in the dataset as it is
disconnected recordset and then i want to make the
changes in the database at one shot.
Can u suggest the way of updating the hierarchy.
And one more thing if i am making the changes through
different controls not asp but in VB then i have to
find the particular child record for the respective
parent record and update that record in the dataset
and then to call the update method, so to get that
record is there any property like Index or something
which can make it easy to retrieve that particular
record and make changes in the dataset.
thanks in advance
Ramanathan
-----Original Message-----
From: Dave Sussman [SMTP:davids@i...]
Sent: Thursday, March 22, 01 3:32 PM
To: ASP+
Subject: [aspx] Re: creation of Hierarchial Recordsets
Yep, that's pretty much the way to do it. You can
remove some code too, by
leaving out a few variables:
myCommand = New ADODataSetCommand("Select * from
publishers",
myConnection)
myCommand.FillDataSet(ds, "Publishers")
myCommand = New ADODataSetCommand("Select * from
titles", myConnection)
myCommand.FillDataSet(ds, "titles")
rel = New DataRelation("PublishersTitles", _
ds.Tables("Publishers").Columns("pub_id"), _
ds.Tables("Titles").Columns("pub_id"))
ds.Relations.Add(rel)
Otherwise that's the expected way. Extracting rows
depends on what you are
doing. You can use the DataRow object to enumerate
through the rows, and
then the GetChildRows method of the data row to get
the child rows for the
selected parent row. This can also be done in
databinding like so:
Publishers.DataSource
ds.Tables("Publishers").DefaultView
Publishers.DataBind()
<asp:Repeater id="Publishers" runat="server">
<template name="ItemTemplate">
<asp:DataList id="Pictures" border="0"
RepeatDirection="vertical"
RepeatColumns="1"
DataSource ='<%# CType(Container.DataItem,
DataRowView).CreateChildView("PublishersTitles") %>'
runat="server">
When binding you use a DataRowView rather than a
DataRow, and the
CreateChildView just extracts the child rows and
creates a view from it.
Dave
"NK Ramanathan" <nkram2000@y...> wrote in message
news:49607@a...
>
> Hi there,
> I am facing problems in creating hiereachial
> recordsets using ado.net and how to retrieve the
> hierarchial recordset.
> Can anybody suggest that whether there is any
command
> like "Shape" of ADO 2.0 which creates a hierarchial
> recordsets.
>
> I am doing it in this way.
>
> qry = "select * from employee"
>
> dsCmd.SelectCommand() = New ADO.ADOCommand(qry,
> adc)
> dscmd.FillDataSet(dset, ptable)
> dtable = dset.Tables(0)
>
> qry = "select * from dept"
>
> dsCmd.SelectCommand() = New ADO.ADOCommand(qry,
> adc)
> dscmd.FillDataSet(dset, ptable)
> dtable1 = dset.tables(1)
>
> childCol
> dset.Tables("emp").Columns("deptid")
> parentCol
> dset.Tables("dept").Columns("deptid")
> ' Create DataRelation.
> reldeptid = New DataRelation("reldeptid",
> parentCol, childCol)
> ' Add the relation to the DataSet.
> dset.Relations.Add(reldeptid)
>
> if this is the correct way then how to retrieve the
> records from the child tables?
>
>
> Thx in advance
> Ramanathan
|
|
 |