Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Attach a DataTable to a DataSet
Message
De
11/03/2005 16:25:01
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Attach a DataTable to a DataSet
Versions des environnements
Environment:
C# 1.1
OS:
Windows 2000 SP4
Network:
Windows NT
Database:
MS SQL Server
Divers
Thread ID:
00995022
Message ID:
00995022
Vues:
53
I have a business object that return the list of contacts to the user interface. Here is the code of the method:
public DataTable getContact ()
{
   // I know, this part should be in the Data Layer...

   SqlConnection conn = new SqlConnection (...);
   DataSet dsContact = new DataSet ();
   SqlDataAdapter adptContact = new SqlDataAdapter ("SELECT * FROM Contact ORDER BY Contact", conn);
   adptContact.Fill (dsContact, "Contact");
   return dsContact.Tables ["Contact"];
}
The user interface should get the list and add it to it's DataSet. A control will then be bounded to this list.

I have some questions:

  • Must I pass through a DataSet and a DataAdapter class to fill a DataTable?
  • I return a DataTable instead of a DataSet because I figure that it is smaller and should be faster. Am I right in this assumption?
  • When a DataTable (or DataSet) is passed like this between layers, what is really passed between the EXE and the DLL, a XML string or the object is marshalled and passed?
  • In the user interface, I would like to put all the tables I get like this in a DataSet instead of defining a property for each one, but I can't get the DataSet to add the DataTable. Here is the code:
    Contact contact = new Contact ();
    DataTable dtContact = contact.getContact ();
    dsMain.Tables.Add (dtContact);   // Exception is throwed here
    Any suggestions?

    TIA
  • Suivant
    Répondre
    Fil
    Voir

    Click here to load this message in the networking platform