Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return DataSet From DataSet
Message
From
19/07/2010 13:36:46
 
General information
Forum:
ASP.NET
Category:
LINQ
Miscellaneous
Thread ID:
01472665
Message ID:
01472952
Views:
51
Another option, since KevinG mentioned it in another post, is to use the .ToTable() method of a DataView. That will give you the structure of your table, even when no rows are returned. Sorry for not thinking of it sooner, but I was just trying to address the exception thrown by the CopyToDataTable() method.
DataTable ResultSet = new DataView(csCOSApp.ActiveProject.dsDataStore.Tables[0], "ProductId > 0", "Sort Criteria if you want it, empty string otherwise", DataViewRowState.None).ToTable();
~~Bonnie




>Thanks Bonnie. This worked great - with one minor change.
>
>
>DataTable ResultSet = csCOSApp.ActiveProject.dsDataStore.Tables[0].Copy();
>
>ResultSet.Rows.Clear();
>csCOSApp.ActiveProject.dsDataStore.Tables[0].Select("ProductId > 0").CopyToDataTable(ResultSet, LoadOption.PreserveChanges, delegate { });
>if (ResultSet.Rows.Count > 0)
>{
>    LoadProducts(ResultSet, true);
>}
>
>ResultSet.Rows.Clear();
>csCOSApp.ActiveProject.dsDataStore.Tables[0].Select("ProductId = 0").CopyToDataTable(ResultSet, LoadOption.PreserveChanges, delegate { });
>if (ResultSet.Rows.Count > 0)
>{
>    LoadParts(ResultSet, true);
>}
>
>
>I was getting "Input array is longer than the number of columns in this table.". Turns out the destination table needs to have the structure all set up. I thought CopyToDataTable would create it.
>
>At any rate, I learned something new.
>
>Thanks!
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform