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. C#
  4. Binding 2 data tables to a single data grid

Binding 2 data tables to a single data grid

Scheduled Pinned Locked Moved C#
csswpfwcftutorialquestion
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.
  • M Offline
    M Offline
    myinstincts
    wrote on last edited by
    #1

    How to bind two data tables which are in the same dataset to a datagrid????Below is tha code i've written so far OleDbDataAdapter da_pay = new OleDbDataAdapter(); DataSet ds_pay = new DataSet(); OleDbCommand pay_cmd = new OleDbCommand("select Group from group_details where [Group]='"+descriptiondpdwnlist .SelectedItem .Value +"'",con2); da_pay.SelectCommand = pay_cmd; da_pay.Fill(ds_pay,"bill_group"); DataTable pay_dt=ds_pay .Tables ["bill_group"]; OleDbCommand pay_cmd1 = new OleDbCommand("select Description from description_details where [Description]='"+descrptndpdnlt .SelectedItem .Text +"'",con2); da_pay.SelectCommand = pay_cmd1; da_pay.Fill(ds_pay ,"Bill_description"); DataTable pay_dt1=ds_pay .Tables ["Bill_description"]; con2.Close();

    P 1 Reply Last reply
    0
    • M myinstincts

      How to bind two data tables which are in the same dataset to a datagrid????Below is tha code i've written so far OleDbDataAdapter da_pay = new OleDbDataAdapter(); DataSet ds_pay = new DataSet(); OleDbCommand pay_cmd = new OleDbCommand("select Group from group_details where [Group]='"+descriptiondpdwnlist .SelectedItem .Value +"'",con2); da_pay.SelectCommand = pay_cmd; da_pay.Fill(ds_pay,"bill_group"); DataTable pay_dt=ds_pay .Tables ["bill_group"]; OleDbCommand pay_cmd1 = new OleDbCommand("select Description from description_details where [Description]='"+descrptndpdnlt .SelectedItem .Text +"'",con2); da_pay.SelectCommand = pay_cmd1; da_pay.Fill(ds_pay ,"Bill_description"); DataTable pay_dt1=ds_pay .Tables ["Bill_description"]; con2.Close();

      P Offline
      P Offline
      padmanabhan N
      wrote on last edited by
      #2

      public void GridBind() { DataTable dtfirst;//your first datatable DataTable dtsecond;//your second datatable DataTable dtOverall = new DataTable(); dtOverall.Columns.Add("id");//name of the first table column dtOverall.Columns.Add("name");//name of the first table column dtOverall.Columns.Add("email");//name of the second table column dtOverall.Columns.Add("phone");//name of the second table column //.. //.. //.. int first = dtfirst.Rows.Count; int second = dtsecond.Rows.Count; int overAllTableCount = (first > second) ? first : second; for (int i = 0; i < overAllTableCount; i++) { int id = 0;//according to the column name and datatype use here string name = string.Empty; string email = string.Empty; string phone = 0; //... //.. //.. if (i < first) { id = int.Parse(dtfirst.Rows[i]["id"].ToString()); name = dtfirst.Rows[i]["name"].ToString(); } if (i < second) { email = second.Rows[i]["email"].ToString(); phone = int.Parse(second.Rows[i]["phone"].ToString()); } DataRow drOverall = dtOverall.NewRow(); drOverall["id"] = id; drOverall["name"] = name; drOverall["email"] = email; drOverall["phone"] = phone; dtOverall.Rows.Add(drOverall); } } //hope you understood

      Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]

      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