|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do I assign a typed DataTable to its typed DataSet?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 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 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 Show quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:%237F0IBLJGHA.2212@TK2MSFTNGP15.phx.gbl... > 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 > 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 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]" <notmyfirstn***@planet.nl> <#7F0IBLJGHA.2***@TK2MSFTNGP15.phx.gbl> | References: <OVCoWKHJGHA.3***@TK2MSFTNGP09.phx.gbl> <eogvkGOJGHA.3***@tk2msftngp13.phx.gbl> | Subject: Re: How do I assign a typed DataTable to its typed DataSet? microsoft.public.dotnet.framework.adonet:119745| 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: <ORgpvQPJGHA.1***@TK2MSFTNGP09.phx.gbl> | 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 Show quote | 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 | | | 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 Show quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:2x1E5kWJGHA.3152@TK2MSFTNGXA02.phx.gbl... > 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]" <notmyfirstn***@planet.nl> > | References: <OVCoWKHJGHA.3***@TK2MSFTNGP09.phx.gbl> > <#7F0IBLJGHA.2***@TK2MSFTNGP15.phx.gbl> > <eogvkGOJGHA.3***@tk2msftngp13.phx.gbl> > | 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: <ORgpvQPJGHA.1***@TK2MSFTNGP09.phx.gbl> > | 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 > | > | > | > 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.) |
|||||||||||||||||||||||