Results 1 to 7 of 7

Thread: Datasets

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    5

    Datasets

    Ive been through all the help files but i can't seem to find what i'm looking for. I need to know how to add a new table to the dataset during run time. If anyone could help me that would be great.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I'm not at my dev machine, but all you need to do is create an instance of the data table class and add it to the dataset's table collection.

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474

    Dim myTable as DataTable
    myDataset.Tables.Add(myTable)


    Didn't mean to repeat you Lethal, It seems we were answering the same time.
    Last edited by Lunatic3; Mar 9th, 2003 at 04:16 PM.

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Lunatic,
    Don't forget you need to call the object's constructor to create an instance.

    Code:
    Dim myTable as New DataTable()

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Oh Sure, Thanks

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    5

    Thanks

    thanks everyone for your help, your advice help but the only problem now is that the new table that is created dose not have the same colums as my first original table. Can you help ?

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Try the Clone() method:

    Code:
    using System;
    using System.Data;
    
    class DataExample {	
        static void Main() {
            DataTable dt = new DataTable("MyDataTable");
            dt.Columns.Add(new DataColumn("Id"));
            DataTable clone = dt.Clone();
    
            foreach(DataColumn c in clone.Columns) {
                Console.WriteLine("Column Name: {0}", c.ColumnName);
            }
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width