+ Reply to Thread
Results 1 to 3 of 3

Thread: bind tables in dataset to a single DataGridView

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    15

    bind tables in dataset to a single DataGridView

    I have created windows Application.In this , I have multiple tables in dataset now i want to bind that to a single DataGridView.Can anybody help me?

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    15
    any help from anyone ?

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    14
    DataGridView1.AutoGenerateColumns = True;
    DataGridView1.DataSource = ds; // dataset
    DataGridView1.DataMember = "TableName"; // table name you need to show
    if you want to show multiple tables, you need to create one datatable or custom object collection out of all tables.

    if two tables with same table schema

    dtAll = dtOne.Copy(); // dtOne = ds.Tables[0]
    dtAll.Merge(dtTwo); // dtTwo = dtOne = ds.Tables[1]

    DataGridView1.AutoGenerateColumns = True;
    DataGridView1.DataSource = dtAll ; // datatable
    sample code to mode all tables

    DataTable dtAll = ds.Tables[0].Copy();
    for (var i = 1; i < ds.Tables.Count; i++)
    {
    dtAll.Merge(ds.Tables[i]);
    }
    DataGridView1.AutoGenerateColumns = True;
    DataGridView1.DataSource = dtAll ;

+ Reply to Thread

Bookmarks

Posting Permissions

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