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. Adding values to datatable

Adding values to datatable

Scheduled Pinned Locked Moved C#
5 Posts 3 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

    want to add new values to datatable rows on each button_click event..i want it in such a way that the new data gets added to the next row,instead of overwriting the first...Below is the code which i wrote Button_Click event() {OleDbDataAdapter da_pay = new OleDbDataAdapter(); DataSet ds_pay = new DataSet(); con2.Open(); da_pay.SelectCommand = pay_cmd2; da_pay.Fill(ds_pay ,"details"); pay_dt=ds_pay .Tables ["details"]; pay_dt.Rows.Add(); con2.Close();} But for every button click event the first row hets overwritten

    V K 2 Replies Last reply
    0
    • M myinstincts

      want to add new values to datatable rows on each button_click event..i want it in such a way that the new data gets added to the next row,instead of overwriting the first...Below is the code which i wrote Button_Click event() {OleDbDataAdapter da_pay = new OleDbDataAdapter(); DataSet ds_pay = new DataSet(); con2.Open(); da_pay.SelectCommand = pay_cmd2; da_pay.Fill(ds_pay ,"details"); pay_dt=ds_pay .Tables ["details"]; pay_dt.Rows.Add(); con2.Close();} But for every button click event the first row hets overwritten

      V Offline
      V Offline
      Vimalsoft Pty Ltd
      wrote on last edited by
      #2

      Check this what you wrote is not Corrent. You must create a Row object and add the row to the datatable http://msdn.microsoft.com/en-us/library/5ycd1034%28VS.80%29.aspx[^] http://www.java2s.com/Tutorial/CSharp/0560__ADO.Net/AddRowtoDataTable.htm[^] http://www.victorchen.info/add-rows-to-a-datatable-in-c/[^]

      Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

      1 Reply Last reply
      0
      • M myinstincts

        want to add new values to datatable rows on each button_click event..i want it in such a way that the new data gets added to the next row,instead of overwriting the first...Below is the code which i wrote Button_Click event() {OleDbDataAdapter da_pay = new OleDbDataAdapter(); DataSet ds_pay = new DataSet(); con2.Open(); da_pay.SelectCommand = pay_cmd2; da_pay.Fill(ds_pay ,"details"); pay_dt=ds_pay .Tables ["details"]; pay_dt.Rows.Add(); con2.Close();} But for every button click event the first row hets overwritten

        K Offline
        K Offline
        kKamel
        wrote on last edited by
        #3

        could you explain more what is happening there??? where is the new data comming from is it a new row from the data base that the old table had gotten its values???what do you expect from pay_dt.Rows.Add(); to do?? try to create data columns same fields as the datatable then a datarow assign the values of the new row you want to add to the created datarow , then add the new datarow to the old dataTable or try the function DataTable.Merger(x) where it merges two dataTables.

        M 1 Reply Last reply
        0
        • K kKamel

          could you explain more what is happening there??? where is the new data comming from is it a new row from the data base that the old table had gotten its values???what do you expect from pay_dt.Rows.Add(); to do?? try to create data columns same fields as the datatable then a datarow assign the values of the new row you want to add to the created datarow , then add the new datarow to the old dataTable or try the function DataTable.Merger(x) where it merges two dataTables.

          M Offline
          M Offline
          myinstincts
          wrote on last edited by
          #4

          I think i am missing out the basic concepts of data table..I selected values from the data source and stored it in a data set in the table details..A datatable was created in the same dataset and when it was connected to the gridview the values where displaying(eventhough i dint specified the column).I thought then if i give pay_dt(which is my data table).rows.add() then new rows eill get added to the datatable and values will also gets added.values are getting added..But it is overwriting the first

          modified on Thursday, August 27, 2009 6:16 AM

          K 1 Reply Last reply
          0
          • M myinstincts

            I think i am missing out the basic concepts of data table..I selected values from the data source and stored it in a data set in the table details..A datatable was created in the same dataset and when it was connected to the gridview the values where displaying(eventhough i dint specified the column).I thought then if i give pay_dt(which is my data table).rows.add() then new rows eill get added to the datatable and values will also gets added.values are getting added..But it is overwriting the first

            modified on Thursday, August 27, 2009 6:16 AM

            K Offline
            K Offline
            kKamel
            wrote on last edited by
            #5

            Well first the values appeared becuase in the grid there is a prop name autogenerateColumns. try to fill the new dataTable with the new data and then databind. Tell me if this worked?? or there is something you need to be explained more

            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