Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding DataTable to DataSet
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01343220
Message ID:
01343269
Vues:
19
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>I found this link http://msmvps.com/blogs/egoldin/archive/2006/12/27/how-to-get-datatable-out-of-sqldatasource.aspx
>
>So, I can get the DataTable.
>
>I need to create a dataset with this data and save it to the session.
>
>Do you know how can I do this?
>
>Can I somehow cast DataTable to DataSet?
>

No, but you can add a DataTable to a DataSet (as long as the DataTable doesn't already belong to another DataSet), ex:
DataSet ds = new DataSet(); 
// Retrieve the table from wherever
DataTable table = new DataTable("TableName");
ds.Tables.Add(table);
If it's already part of a DataSet (ex. you can tell by checking to see if the tables DataSet property is null or not), you'll get an error if you try assigning it to another DataSet. If that's the case, you can copy the DataTable, then add the copy:
if (table.DataSet != null)
{
    DataTable newTable = table.Copy()
    ds.Tables.Add(newTable);
}
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform