Thursday, March 16, 2006

convert a dataview to a dataset dataview to datatable

public static DataTable DataViewAsDataTable( DataView dv)
{
DataTable dt = dv.Table.Clone();
foreach (DataRowView drv in dv)
dt.ImportRow(drv.Row);
return dt;
}


DataSet dsFiltered = new DataSet(); //create a new dataset
dsFiltered.Tables.Add(AppUtil.DataViewAsDataTable (dvResult) ); //fill the dataset with the sorted results

16 Comments:

At 4:00 AM, Anonymous Anonymous said...

Good, it is very helpful

 
At 1:16 PM, Blogger Andrew said...

Is iterating through the dataviewrows really the only way to do this?

I haven't found a better way to do it (after 15 minutes of searching) so I'm guessing there isn't one. But it seems a bit funny that you have to iterate through the datarows. Thanks anyway - this is the best solution I found so far.

Software Dorset

 
At 8:19 AM, Blogger Unknown said...

This is better me thinks..
ds.Tables.Add(dv.Table.Copy());

 
At 10:17 AM, Anonymous Anonymous said...

Thaks dude...i couldnt figure out a better one...

 
At 1:22 PM, Anonymous Anonymous said...

An easier way:
DataTable newOne = dv.ToTable();
Available in .NET 2.0 and above only.

 
At 10:45 PM, Anonymous Anonymous said...

Thank you, dorked around with this forever... was trying to avoid iteration, but apparently that is the only choice in 1.1

 
At 10:24 PM, Anonymous Anonymous said...

Thanks a lot mate...

this solution was exactly that i was looking for....Hat's OFF

 
At 1:21 PM, Anonymous Anonymous said...

awesome thank you. i guess there is no dv.toTable() in 1.1. 2.0 makes it easier.

 
At 10:54 AM, Anonymous Anonymous said...

Thanks friend. I tried multiple ways to create dataset from Dataview.. Yours is the best one..

 
At 8:33 PM, Anonymous Anonymous said...

You know ,I have some wonderland Gold,and my friend

also has some wonderland online Gold,do you kouw they

have the same meaning,Both of them can be called
wonderland money,I just want to
buy wonderland Gold,because there are many
cheap wonderland online Gold

 
At 8:02 AM, Anonymous Amol Pandit said...

Thanx dude Its working for me :D

 
At 12:34 PM, Anonymous Anonymous said...

This is exactly what I needed. Thank you so much!

 
At 5:24 AM, Anonymous Dattaprasad Kulkarni said...

Thanks! I was searching for same since long time!! Thanks for this solution !!

 
At 8:11 PM, Anonymous Anonymous said...

Thanks that really helped.

 
At 10:17 PM, Anonymous Anonymous said...

Awesome solution! Thanks mate...

 
At 7:16 AM, Blogger Jineesh said...

thankuuuuuuuu very much.......
i m searching this for so many sites at last u finish my searching ,tanku.....

 

Post a Comment

<< Home