PC Review


Reply
Thread Tools Rate Thread

Dataset to typed dataset ?

 
 
=?Utf-8?B?SmFyb2Q=?=
Guest
Posts: n/a
 
      13th Jun 2005
Hey
I am using SqlHelper and I need to convert returned dataset to a typed
dataset. Any ideas how can I do this ?
Jarod
 
Reply With Quote
 
 
 
 
W.G. Ryan eMVP
Guest
Posts: n/a
 
      13th Jun 2005
Jarod - why not just fill the Typed DataSet in the first place. There's not
a direct convert function and I'm pretty sure you'd have to write your own
dataset to accomplish this implementing IConvertible for instance. I've
seen a lot of people do stuff like pass in a regular dataset to SqlHelper,
then loop through it copying the rows and then putting them in the typed
dataset (there's so much wrong with approaches like this it's hard to know
where to begin). It's a LOT easier to just fill the typed dataset from the
get go. DataSets are often pretty big too and consume a good bit of memory,
so creating one, just so you can convert it to another type and then destroy
it is definitely not an approach that will scale well,

As an aside, check this out:

private void button1_Click(object sender, System.EventArgs e) {

Dataset1 dss = new Dataset1();

FillDataSet(dss);

}

private void FillDataSet(DataSet ds){

MessageBox.Show(ds.Tables.Count.ToString());

}



Notice that I'm passing in a Typed DataSet but the signature is for a
DataSet. It works b/c the typed dataset is still of type dataset so it will
still work. With SqlHelper, you can specify your tablemappings and
columnmappings, but essentially the same approach can work for you there.


--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Jarod" <(E-Mail Removed)> wrote in message
news:4175A9BC-0864-46C6-A7C1-(E-Mail Removed)...
> Hey
> I am using SqlHelper and I need to convert returned dataset to a typed
> dataset. Any ideas how can I do this ?
> Jarod



 
Reply With Quote
 
=?Utf-8?B?SmFyb2Q=?=
Guest
Posts: n/a
 
      13th Jun 2005
> Jarod - why not just fill the Typed DataSet in the first place. There's not
> a direct convert function and I'm pretty sure you'd have to write your own
> dataset to accomplish this implementing IConvertible for instance. I've
> seen a lot of people do stuff like pass in a regular dataset to SqlHelper,
> then loop through it copying the rows and then putting them in the typed
> dataset (there's so much wrong with approaches like this it's hard to know
> where to begin). It's a LOT easier to just fill the typed dataset from the
> get go. DataSets are often pretty big too and consume a good bit of memory,
> so creating one, just so you can convert it to another type and then destroy
> it is definitely not an approach that will scale well,
>
> As an aside, check this out:
>
> private void button1_Click(object sender, System.EventArgs e) {
>
> Dataset1 dss = new Dataset1();
>
> FillDataSet(dss);
>
> }
>
> private void FillDataSet(DataSet ds){
>
> MessageBox.Show(ds.Tables.Count.ToString());
>
> }



SqlHelper.ExecuteDataSer(...) it returns DataSet ( untyped so I need to
find a way for it to convert. My datasets will be really small only a few
rows. So the scalability don't matters. Maybe you can show me how to invoke
stored procedure by using sqlhelper and then use typed dataset.
Jarod
 
Reply With Quote
 
W.G. Ryan eMVP
Guest
Posts: n/a
 
      13th Jun 2005
Jarod - the FillDataSet was the method I was speaking of. In practice, I
actually augmented it to have a FillTypedDataSet method and the only
difference is essentially that I have another parameter for the
tablemappings/columnmappings.

Also, although this isn't exactly what you asked origianlly, just as an FYI,
you can use a TypedDataset in the place of where you're expecting an
Untyped one - just not the other way around:

private void button1_Click(object sender, System.EventArgs e) {

DataSet dss = FillDataSet();

MessageBox.Show(dss.Tables.Count.ToString());

}

private Dataset1 FillDataSet(){

Dataset1 ds = new Dataset1();

DataTable dt = new DataTable();

DataColumn dc = new DataColumn("TestColumn", typeof(System.String));

dt.Columns.Add(dc);

ds.Tables.Add(dt);

DataRow dro = dt.NewRow();

dro[0] = "Bill Ryan";

dt.Rows.Add(dro);

return ds;

}



But ultimatey my point is that in this instance, you can easily add an
augmented method to your SqlHelper class as we did, FillTypedDataSet and
since it's a reference type, when you pass it in, any changes made to it
will be made to the origianl (I know, many purists say that you should use
return values instead but I honestly don't see anything wrong with this
approach).

On a scale of 1-10, it's about a 3 to add this in, and you can reuse it
everywhere (Typed Dataset have many many things to like about them, and not
having to worry about getting the colum names right is one of the bigger
ones) so it's a great component to build that you can use all over the
place. I'll be glad to walk you through it.



Cheers,



Bill


--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Jarod" <(E-Mail Removed)> wrote in message
news:FEE4EDEF-C1B7-4F2B-84B4-(E-Mail Removed)...
>> Jarod - why not just fill the Typed DataSet in the first place. There's
>> not
>> a direct convert function and I'm pretty sure you'd have to write your
>> own
>> dataset to accomplish this implementing IConvertible for instance. I've
>> seen a lot of people do stuff like pass in a regular dataset to
>> SqlHelper,
>> then loop through it copying the rows and then putting them in the typed
>> dataset (there's so much wrong with approaches like this it's hard to
>> know
>> where to begin). It's a LOT easier to just fill the typed dataset from
>> the
>> get go. DataSets are often pretty big too and consume a good bit of
>> memory,
>> so creating one, just so you can convert it to another type and then
>> destroy
>> it is definitely not an approach that will scale well,
>>
>> As an aside, check this out:
>>
>> private void button1_Click(object sender, System.EventArgs e) {
>>
>> Dataset1 dss = new Dataset1();
>>
>> FillDataSet(dss);
>>
>> }
>>
>> private void FillDataSet(DataSet ds){
>>
>> MessageBox.Show(ds.Tables.Count.ToString());
>>
>> }

>
>
> SqlHelper.ExecuteDataSer(...) it returns DataSet ( untyped so I need to
> find a way for it to convert. My datasets will be really small only a few
> rows. So the scalability don't matters. Maybe you can show me how to
> invoke
> stored procedure by using sqlhelper and then use typed dataset.
> Jarod



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      14th Jun 2005
Jarod,

Have a look in this message where I made a sample for Claus.

http://groups-beta.google.com/group/...8a2222e2?hl=en

I hope this helps a little bit.

Cor


 
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
Unable to cast object of type 'System.Data.DataSet' to Typed DataSet Optimus Microsoft VB .NET 1 31st Jan 2006 06:26 AM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ADO .NET 7 9th Dec 2003 02:50 PM
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
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
Cast weakly typed DataSet to a strongly typed dataset??? Microsoft Dot NET 0 18th Sep 2003 10:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:12 PM.