Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. DatagridView , set datasource from 2 or more related tables

DatagridView , set datasource from 2 or more related tables

Scheduled Pinned Locked Moved Visual Basic
databasequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dcode25
    wrote on last edited by
    #1

    In DatagridView , is possible to set as datasource 2 or more related tables from a dataset ? And more , to use a Sum of a field as datagridview column ? For illustration i have 2 tables in my dataset: Table 1 : St_ID (primary key ) , Name Table 2 : MID ( Primary Key) , Student (related with ST_ID) , QTy , Date in table 2 for a student there are 1 or multiple registration with different QTY and Date. Now i want to display in datagridview 2 columns : Name Sum(QTY) But i don't want to query directly the database , but i want to use only tables in dataset. Thank you !

    D 1 Reply Last reply
    0
    • D dcode25

      In DatagridView , is possible to set as datasource 2 or more related tables from a dataset ? And more , to use a Sum of a field as datagridview column ? For illustration i have 2 tables in my dataset: Table 1 : St_ID (primary key ) , Name Table 2 : MID ( Primary Key) , Student (related with ST_ID) , QTy , Date in table 2 for a student there are 1 or multiple registration with different QTY and Date. Now i want to display in datagridview 2 columns : Name Sum(QTY) But i don't want to query directly the database , but i want to use only tables in dataset. Thank you !

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The DataSet class doesn't have a Select method to allow you to do this easily. If your DataSet, which is a collection of DataTable and DataRelation objects, has those relationship objects in it, you can build your own table by enumerating the Name records in the "Table1" table, and lookup up the keys in the "Table2" table. You'd be able to interate over those records to build the Sum you want, then just add the Name and Sum to the DataTable you're building. Or, you can simplify this greatly by having the database do it and just hand to you table, just like the SELECT commands you executed to get these tables in the first place.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups