PC Review


Reply
Thread Tools Rate Thread

How do I assign a typed DataTable to its typed DataSet?

 
 
A.M-SG
Guest
Posts: n/a
 
      29th Jan 2006
Hi,

The following code:

TypedDataSet typedDS = new TypedDataSet();
TypedDataSet.TypedDataTable typedDT;
//
// Code to fill typedDT
//
typedDS.TypedDataTable = typedDT; // Colmpiler error!

gives me a compiler error:
Property or indexer cannot be assigned to -- it is read only

What is the proper way to assign a typed DataTable to its typed DataSet?

Thank you,
Alan



 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      29th Jan 2006
Alan,

It is in my idea already in it.

If you want to add it in a strongly typed way, than you have in my idea to
inherit it as class and add that datatable description.

I hope this helps although I am not sure what your are up to.

Cor


 
Reply With Quote
 
A.M-SG
Guest
Posts: n/a
 
      29th Jan 2006
Hi Cor,



My question is with regards to ADO.NET 2.0 and VS 2005.



New in ADO.NET 2.0, you can instantiate datatables independently and
pass/stream it to different physical tiers.



My question is when I have an independent typed datatable, how can I
associate it to a typed datatable. Please consider the fact that the typed
dataset that I am talking about is the parent type for that typed datatable.



Regards,

Alan




"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Alan,
>
> It is in my idea already in it.
>
> If you want to add it in a strongly typed way, than you have in my idea to
> inherit it as class and add that datatable description.
>
> I hope this helps although I am not sure what your are up to.
>
> Cor
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      29th Jan 2006
Alan,

You have created a typed dataset and a typed datatable
In windowsform VS2005 are that a classes which you can see with the file
name xx.designer.cs

As soon as you start to add something to one where not is a typed method
for, than it becomes in my opinion part of adding untyped that to it.

ds.Tables.Add(mytypedDataset)

To use it, you will than probably constantly have to use the casting or set
a new reference.

MyTable = (TypedDataTableName) ds.Tables[x];

Not tried just my idea about this.

Cor


 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      30th Jan 2006
Hi Alan,

As Cor has mentioned, one way is to directly add the Table into the Typed
DataSet's Tables collection, however, that make it necessary to explicitlyl
cast it when accesing it again from the Tables Collection.

Also, the 2.0 DataTable class provide a "Load" function which can load data
from an IDataReader instance, so you can create a IDataReader instance from
an existing TypeDataTable through its CreateDataReader method. e.g:

==================
DataSet1 ds1 = new DataSet1();

DataSet1TableAdapters.CategoriesTableAdapter tda = new
DataSet1TableAdapters.CategoriesTableAdapter();
DataSet1.CategoriesDataTable ct = tda.GetData();

ds1.Categories.Load(ct.CreateDataReader());

GridView1.DataSource = ds1.Categories;
GridView1.DataBind();
===============

This makes a bit overhead, but will work in case you have an existing Typed
DataTable which has been filled indepently from Typed DataSet and want to
merge it into the dataset...

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Cor Ligthert [MVP]" <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<#(E-Mail Removed)>
<(E-Mail Removed)>
| Subject: Re: How do I assign a typed DataTable to its typed DataSet?
| Date: Sun, 29 Jan 2006 17:51:39 +0100
| Lines: 21
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| Message-ID: <(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: ip3e830773.speed.planet.nl 62.131.7.115
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.adonet:119745
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Alan,
|
| You have created a typed dataset and a typed datatable
| In windowsform VS2005 are that a classes which you can see with the file
| name xx.designer.cs
|
| As soon as you start to add something to one where not is a typed method
| for, than it becomes in my opinion part of adding untyped that to it.
|
| ds.Tables.Add(mytypedDataset)
|
| To use it, you will than probably constantly have to use the casting or
set
| a new reference.
|
| MyTable = (TypedDataTableName) ds.Tables[x];
|
| Not tried just my idea about this.
|
| Cor
|
|
|

 
Reply With Quote
 
A.M
Guest
Posts: n/a
 
      30th Jan 2006
Hi Steven,



The DataTable is a very big one, so having two instance of it would be a
waste.



I think I should do the plumbing between datasets and datatables at the
object instance level, not data level.



All I am trying to do is asking the DataSet to drop its existing empty
datatable object and leave it to garbage collector, and then use the new
datatable object with data. Can I do that?



Thank you for help,

Alan







"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Alan,
>
> As Cor has mentioned, one way is to directly add the Table into the Typed
> DataSet's Tables collection, however, that make it necessary to
> explicitlyl
> cast it when accesing it again from the Tables Collection.
>
> Also, the 2.0 DataTable class provide a "Load" function which can load
> data
> from an IDataReader instance, so you can create a IDataReader instance
> from
> an existing TypeDataTable through its CreateDataReader method. e.g:
>
> ==================
> DataSet1 ds1 = new DataSet1();
>
> DataSet1TableAdapters.CategoriesTableAdapter tda = new
> DataSet1TableAdapters.CategoriesTableAdapter();
> DataSet1.CategoriesDataTable ct = tda.GetData();
>
> ds1.Categories.Load(ct.CreateDataReader());
>
> GridView1.DataSource = ds1.Categories;
> GridView1.DataBind();
> ===============
>
> This makes a bit overhead, but will work in case you have an existing
> Typed
> DataTable which has been filled indepently from Typed DataSet and want to
> merge it into the dataset...
>
> Regards,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
> --------------------
> | From: "Cor Ligthert [MVP]" <(E-Mail Removed)>
> | References: <(E-Mail Removed)>
> <#(E-Mail Removed)>
> <(E-Mail Removed)>
> | Subject: Re: How do I assign a typed DataTable to its typed DataSet?
> | Date: Sun, 29 Jan 2006 17:51:39 +0100
> | Lines: 21
> | X-Priority: 3
> | X-MSMail-Priority: Normal
> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
> | X-RFC2646: Format=Flowed; Response
> | Message-ID: <(E-Mail Removed)>
> | Newsgroups: microsoft.public.dotnet.framework.adonet
> | NNTP-Posting-Host: ip3e830773.speed.planet.nl 62.131.7.115
> | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
> | Xref: TK2MSFTNGXA02.phx.gbl
> microsoft.public.dotnet.framework.adonet:119745
> | X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
> |
> | Alan,
> |
> | You have created a typed dataset and a typed datatable
> | In windowsform VS2005 are that a classes which you can see with the file
> | name xx.designer.cs
> |
> | As soon as you start to add something to one where not is a typed method
> | for, than it becomes in my opinion part of adding untyped that to it.
> |
> | ds.Tables.Add(mytypedDataset)
> |
> | To use it, you will than probably constantly have to use the casting or
> set
> | a new reference.
> |
> | MyTable = (TypedDataTableName) ds.Tables[x];
> |
> | Not tried just my idea about this.
> |
> | Cor
> |
> |
> |
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      1st Feb 2006
Thanks for your reply Alan,

Yes, it's waste of resource to hold two datatable in memory. For the typed
DataSet's Typed DataTAble property, it is readonly and is initialized at
the typed dataset's creation time.... So we can not manually drop it and
replace with another on the fly. Also, as for the using Load method to
copy the data from the existing datatable, we can also explicitly dispose
that datatable after to import its data into the typed dataset's typed
datatable property.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ADO .NET 2 31st Oct 2003 01:05 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ASP .NET 2 31st Oct 2003 01:05 PM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ASP .NET 2 31st Oct 2003 02:42 AM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft Dot NET Framework 2 31st Oct 2003 02:39 AM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft C# .NET 1 31st Oct 2003 02:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:44 AM.