• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2403
  • Last Modified:

How do I add DataTables to a DataSet in ASP.NET 2.0 / C#?

I would like to use a DataSet instead of a bunch of scattered DataTables. How do I add DataTables to a DataSet and reference those tables from the DataSet? Here is an example that I'm trying to do:

        DataSet dbTable = new DataSet("Structure");

        DataTable fileTable = new DataTable("Files");
        fileTable.Columns.Add("Name", typeof(String));
        fileTable.Columns.Add("Size", typeof(Double));
        fileTable.Columns.Add("Directory", typeof(Double));

        DataTable directoryTable = new DataTable("Directories");
        directoryTable.Columns.Add("Name", typeof(string));
        directoryTable.Columns.Add("Parent", typeof(string));
        directoryTable.Columns.Add("CreationTime", typeof(DateTime));
0
bemara57
Asked:
bemara57
2 Solutions
 
Elvio Lujan.Net Senior DeveloperCommented:
dbTable.Tables.Add(fileTable)
dbTable.Tables.Add(directoryTable)
0
 
David H.H.LeeCommented:
Dear bemara57,
Use this instead:
DataSet dbTable = new DataSet("Structure");

dbTable.Tables.Add(fileTable);
dbTable.Tables.Add(directoryTable);

dbTable .Tables["Files"] - table "Files"
dbTable .Tables["Directories"] - table "Directories"
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now