Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset

N

Nedu N

Hi All,
I am facing problem in copying content of table from a untyped dataset into
to a table inside the typed dataset. I wanted to copy the data into typed
dataset in order to ease the further processing using typed references.

DataSet ds = getDataFromDB(); - i am getting the dataset ds from a
webservice

I have got MyXSD which decsribes the shcema for the table which i am getting
from the webservice
and i am trying to cast like following
MyXSD myds = (MyXSD)ds; ==> but giving me invalid exception error

And i tried copying the table from ds into myds like
myds.Tables[0] = ds.Tables[0];

but it is giving me error saying myds.Tables[0] is READ ONLY....

I tried ImportRow also but getting errors and i don't want to manually go
thru the rows and put into my Typed dataset..

Thanks for your help.

Nedu
 
K

Kevin Yu [MSFT]

Hi Nedu N,

Based on my understanding, you're importing rows from a DataSet to a strong
typed DataSet. Because MyXSD is a class derived from DataSet, casting from
base class to derived class is not allowed. And the table collection
property in a DataSet is readonly, so you can only make changes to it throw
public methods of it.

Since you want to import rows to the table, which already exists in the
typed DataSet, I think you have to use ImportRow() method of a table and
import rows one by one. I've written a short example to achieve this:
(Dataset1 is a Strong Typed Dataset and contains a table named Employees)

Dataset1 tds = new Dataset1();
DataSet ds = new DataSet();
sda.Fill(ds, "Employees");
foreach(DataRow dr in ds.Tables["Employees"].Rows)
{
tds.Employees.ImportRow(dr);
}

HTH

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Reply-To: "Nedu N" <[email protected]>
| From: "Nedu N" <[email protected]>
| Subject: Ccopying a datatable content from an untyped dataset into a
table which is inside a typed dataset
| Date: Thu, 30 Oct 2003 14:36:12 -0800
| Lines: 28
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.pub
lic.dotnet.framework.adonet,microsoft.public.dotnet.framework.aspnet,microso
ft.public.dotnet.framework.aspnet.datagridcontrol,microsoft.public.dotnet.la
nguages.csharp,micros
| NNTP-Posting-Host: machine45.qwest.net 204.154.239.45
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:57535
microsoft.public.dotnet.framework.adonet:64949
microsoft.public.dotnet.framework.aspnet:187679
microsoft.public.dotnet.framework.aspnet.datagridcontrol:7272
microsoft.public.dotnet.languages.csharp:195533
microsoft.public.dotnet.faqs:12234
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Hi All,
| I am facing problem in copying content of table from a untyped dataset
into
| to a table inside the typed dataset. I wanted to copy the data into typed
| dataset in order to ease the further processing using typed references.
|
| DataSet ds = getDataFromDB(); - i am getting the dataset ds from a
| webservice
|
| I have got MyXSD which decsribes the shcema for the table which i am
getting
| from the webservice
| and i am trying to cast like following
| MyXSD myds = (MyXSD)ds; ==> but giving me invalid exception error
|
| And i tried copying the table from ds into myds like
| myds.Tables[0] = ds.Tables[0];
|
| but it is giving me error saying myds.Tables[0] is READ ONLY....
|
| I tried ImportRow also but getting errors and i don't want to manually go
| thru the rows and put into my Typed dataset..
|
| Thanks for your help.
|
| Nedu
|
|
|
|
|
 
C

Chris Taylor

Hi,

I believe (read that as I have not tried it!) that you can accomplish this
with the Merge member of the DataSet.

DataSet ds = getDataFromDB();
MyDataSet myds = new MyDataSet();

myds.Merge( ds );

For the cast to work your getDataFromDB() would have to actually be creating
a strongly typed dataset and merely return it as a generic DataSet.

Hope this helps

Chris Taylor
 
K

Kevin Yu [MSFT]

Thanks for Chris's reply.

Merging is also a very good method to achieve this. However, you have to
make sure that the two tables in both DataSets have the same TableName.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Chris Taylor" <[email protected]>
| References: <[email protected]>
| Subject: Re: Ccopying a datatable content from an untyped dataset into a
table which is inside a typed dataset
| Date: Fri, 31 Oct 2003 04:39:14 +0200
| Lines: 50
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.pub
lic.dotnet.framework.adonet,microsoft.public.dotnet.framework.aspnet,microso
ft.public.dotnet.framework.aspnet.datagridcontrol,microsoft.public.dotnet.la
nguages.csharp,micros
| NNTP-Posting-Host: 217-16-232-123.dyn-pool.spidernet.net 217.16.232.123
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:57547
microsoft.public.dotnet.framework.adonet:64961
microsoft.public.dotnet.framework.aspnet:187720
microsoft.public.dotnet.framework.aspnet.datagridcontrol:7273
microsoft.public.dotnet.languages.csharp:195588
microsoft.public.dotnet.faqs:12235
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Hi,
|
| I believe (read that as I have not tried it!) that you can accomplish this
| with the Merge member of the DataSet.
|
| DataSet ds = getDataFromDB();
| MyDataSet myds = new MyDataSet();
|
| myds.Merge( ds );
|
| For the cast to work your getDataFromDB() would have to actually be
creating
| a strongly typed dataset and merely return it as a generic DataSet.
|
| Hope this helps
|
| Chris Taylor
| | > Hi All,
| > I am facing problem in copying content of table from a untyped dataset
| into
| > to a table inside the typed dataset. I wanted to copy the data into
typed
| > dataset in order to ease the further processing using typed references.
| >
| > DataSet ds = getDataFromDB(); - i am getting the dataset ds from a
| > webservice
| >
| > I have got MyXSD which decsribes the shcema for the table which i am
| getting
| > from the webservice
| > and i am trying to cast like following
| > MyXSD myds = (MyXSD)ds; ==> but giving me invalid exception error
| >
| > And i tried copying the table from ds into myds like
| > myds.Tables[0] = ds.Tables[0];
| >
| > but it is giving me error saying myds.Tables[0] is READ ONLY....
| >
| > I tried ImportRow also but getting errors and i don't want to manually
go
| > thru the rows and put into my Typed dataset..
| >
| > Thanks for your help.
| >
| > Nedu
| >
| >
| >
| >
|
|
|
 
K

Kevin Yu [MSFT]

Hi Nedu N,

I'd like to know if this issue has been resolved. I'm still monitoring on
it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| Reply-To: "Nedu N" <[email protected]>
| From: "Nedu N" <[email protected]>
| Subject: Ccopying a datatable content from an untyped dataset into a
table which is inside a typed dataset
| Date: Thu, 30 Oct 2003 14:36:12 -0800
| Lines: 28
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.pub
lic.dotnet.framework.adonet,microsoft.public.dotnet.framework.aspnet,microso
ft.public.dotnet.framework.aspnet.datagridcontrol,microsoft.public.dotnet.la
nguages.csharp,micros
| NNTP-Posting-Host: machine45.qwest.net 204.154.239.45
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:57535
microsoft.public.dotnet.framework.adonet:64949
microsoft.public.dotnet.framework.aspnet:187679
microsoft.public.dotnet.framework.aspnet.datagridcontrol:7272
microsoft.public.dotnet.languages.csharp:195533
microsoft.public.dotnet.faqs:12234
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Hi All,
| I am facing problem in copying content of table from a untyped dataset
into
| to a table inside the typed dataset. I wanted to copy the data into typed
| dataset in order to ease the further processing using typed references.
|
| DataSet ds = getDataFromDB(); - i am getting the dataset ds from a
| webservice
|
| I have got MyXSD which decsribes the shcema for the table which i am
getting
| from the webservice
| and i am trying to cast like following
| MyXSD myds = (MyXSD)ds; ==> but giving me invalid exception error
|
| And i tried copying the table from ds into myds like
| myds.Tables[0] = ds.Tables[0];
|
| but it is giving me error saying myds.Tables[0] is READ ONLY....
|
| I tried ImportRow also but getting errors and i don't want to manually go
| thru the rows and put into my Typed dataset..
|
| Thanks for your help.
|
| Nedu
|
|
|
|
|
 
N

Nedu N

Thanks Kevin..it worked...


Kevin Yu said:
Hi Nedu N,

Based on my understanding, you're importing rows from a DataSet to a strong
typed DataSet. Because MyXSD is a class derived from DataSet, casting from
base class to derived class is not allowed. And the table collection
property in a DataSet is readonly, so you can only make changes to it throw
public methods of it.

Since you want to import rows to the table, which already exists in the
typed DataSet, I think you have to use ImportRow() method of a table and
import rows one by one. I've written a short example to achieve this:
(Dataset1 is a Strong Typed Dataset and contains a table named Employees)

Dataset1 tds = new Dataset1();
DataSet ds = new DataSet();
sda.Fill(ds, "Employees");
foreach(DataRow dr in ds.Tables["Employees"].Rows)
{
tds.Employees.ImportRow(dr);
}

HTH

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Reply-To: "Nedu N" <[email protected]>
| From: "Nedu N" <[email protected]>
| Subject: Ccopying a datatable content from an untyped dataset into a
table which is inside a typed dataset
| Date: Thu, 30 Oct 2003 14:36:12 -0800
| Lines: 28
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups:
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.adonet,microsoft.public.dotnet.framework.aspnet,microsoft.public.dotnet.framework.aspnet.datagridcontrol,microsoft.public.dotnet.la
nguages.csharp,micros
| NNTP-Posting-Host: machine45.qwest.net 204.154.239.45
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:57535
microsoft.public.dotnet.framework.adonet:64949
microsoft.public.dotnet.framework.aspnet:187679
microsoft.public.dotnet.framework.aspnet.datagridcontrol:7272
microsoft.public.dotnet.languages.csharp:195533
microsoft.public.dotnet.faqs:12234
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Hi All,
| I am facing problem in copying content of table from a untyped dataset
into
| to a table inside the typed dataset. I wanted to copy the data into typed
| dataset in order to ease the further processing using typed references.
|
| DataSet ds = getDataFromDB(); - i am getting the dataset ds from a
| webservice
|
| I have got MyXSD which decsribes the shcema for the table which i am
getting
| from the webservice
| and i am trying to cast like following
| MyXSD myds = (MyXSD)ds; ==> but giving me invalid exception error
|
| And i tried copying the table from ds into myds like
| myds.Tables[0] = ds.Tables[0];
|
| but it is giving me error saying myds.Tables[0] is READ ONLY....
|
| I tried ImportRow also but getting errors and i don't want to manually go
| thru the rows and put into my Typed dataset..
|
| Thanks for your help.
|
| Nedu
|
|
|
|
|
 
S

Sachi

Hi Kevin,
I am having same kind of problem. But mine is quiet
different. Will you please check and respond to my thread?

Thread: Error while updating Posted: 09/11/2003

Thanks and Regards,
Sachi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top