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. problem with data table

problem with data table

Scheduled Pinned Locked Moved C#
helpquestion
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

    I am filling my datatable initially and databinding it to data gridview.code is written in button_click event.I am selecting an item from dropdownlist and when the button is clicked it is getting stored in the table.My problem is that the secondly selected item from dropdownlist is overwriting the first selected item instead of appending in the new row.I know some looping has to be done, but how and where? OleDbCommand pay_cmd2 = new OleDbCommand("select group_details.Group,description_details.Description,description_details.Unit_price from group_details,description_details where description_details.Description='" + descrptndpdnlt .SelectedItem .Value + "' AND group_details.Group_id=(select Group_id from description_details where Description='" + descrptndpdnlt .SelectedItem .Value + "')", con2); This is my code da_pay.SelectCommand = pay_cmd2; da_pay.Fill(ds_pay ,"details"); DataTable pay_dt=ds_pay .Tables ["details"]; con2.Close(); GridView2.DataSource = pay_dt; GridView2.DataBind();

    B 1 Reply Last reply
    0
    • M myinstincts

      I am filling my datatable initially and databinding it to data gridview.code is written in button_click event.I am selecting an item from dropdownlist and when the button is clicked it is getting stored in the table.My problem is that the secondly selected item from dropdownlist is overwriting the first selected item instead of appending in the new row.I know some looping has to be done, but how and where? OleDbCommand pay_cmd2 = new OleDbCommand("select group_details.Group,description_details.Description,description_details.Unit_price from group_details,description_details where description_details.Description='" + descrptndpdnlt .SelectedItem .Value + "' AND group_details.Group_id=(select Group_id from description_details where Description='" + descrptndpdnlt .SelectedItem .Value + "')", con2); This is my code da_pay.SelectCommand = pay_cmd2; da_pay.Fill(ds_pay ,"details"); DataTable pay_dt=ds_pay .Tables ["details"]; con2.Close(); GridView2.DataSource = pay_dt; GridView2.DataBind();

      B Offline
      B Offline
      baranils
      wrote on last edited by
      #2

      Hello I have no experience with datagrid But for DataGridView I'm sure about TWO think 1 : you must set the datasource to null before to reassign it GridView2.DataSource = null; GridView2.DataSource = pay_dt; 2 : this is not necessary : GridView2.DataBind();

      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