Results 1 to 5 of 5

Thread: DataSet vs. DataGrid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Thailand
    Posts
    221

    DataSet vs. DataGrid

    If I have more than one table containing in DataSet, how can I bind to DataGrid? I mean some column bing to 1 table, another column bind to second table.

    Thank you,
    Teeravee Sirinapasawasdee
    Gestalt IT Consulting Group
    Growth Your Business With e-Process

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Is there any relationship between the tables?

  3. #3
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    You know I don't think I've ever tried it that way. I usually just create a seperate table in the dataset that is a JOIN of the tables I want to display.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Thailand
    Posts
    221
    I've defined relationship in dataset.
    Teeravee Sirinapasawasdee
    Gestalt IT Consulting Group
    Growth Your Business With e-Process

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    From the Help file under "Binding the Windows Form Datagrid to a Data Source:
    To data-bind the DataGrid control to multiple tables in a dataset in the designer

    Set the control's DataSource property to the object containing the data items you want to bind to.
    If the dataset contains related tables (that is, if it contains a relation object), set the DataMember property to the name of the parent table.
    Write code to fill the dataset.

    To data-bind the DataGrid control programmatically


    Write code to fill the dataset. For details, see Step 3 of the procedure "To data-bind the DataGrid control to a single table in the designer" above.
    Call the DataGrid control's SetDataBinding method, passing it the data source and a data member. If you do not need to explicitly pass a data member, pass an empty string.
    Note If you are binding the grid for the first time, you can set the control's DataSource and DataMember properties. However, you cannot reset these properties once they have been set. Therefore, it is recommended that you always use the SetDataBinding method.
    The following example shows how you can programmatically bind to the Customers table in a dataset called DsCustomers1:

    ' Visual Basic
    DataGrid1.SetDataBinding(DsCustomers1, "Customers")

    // C#
    DataGrid1.SetDataBinding(DsCustomers1, "Customers");
    If the Customers table is the only table in the dataset, you could alternatively bind the grid this way:

    ' Visual Basic
    DataGrid1.SetDataBinding(DsCustomers1, "")

    // C#
    DataGrid1.SetDataBinding(DsCustomers1, "");
    (Optional) Add the appropriate table styles and column styles to the grid. If there are no table styles, you will see the table, but with minimal formatting and with all columns visible.

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