Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Attach a DataTable to a DataSet
Message
From
11/03/2005 16:25:01
 
 
To
All
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Attach a DataTable to a DataSet
Environment versions
Environment:
C# 1.1
OS:
Windows 2000 SP4
Network:
Windows NT
Database:
MS SQL Server
Miscellaneous
Thread ID:
00995022
Message ID:
00995022
Views:
52
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
  • Next
    Reply
    Map
    View

    Click here to load this message in the networking platform