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