How to edit Dataset value (NOT DATA GRID)
-
Hi All, i want to edit DataSet value before binding to GridView. How can i do that..? conn.open(); string result="select name,address,age"; sqlCommand cmnd=new sqlCommand(result); sqlDataAdapter ad=new sqlDataAdapter(result,conn); DataSet ds=new DataSet(); result.Connection=conn; ad.SelectCommand=result; // in here i want to edit (divide age value by 2) before bind data to gridview. ad.fill(ds); GridView1.DataSource=ds; GridView1.DataBind(); conn.close(); i want to divide age value by 2 before bind data to gridview.How can i do that...??? Thank you very much .....
CheeN
-
Hi All, i want to edit DataSet value before binding to GridView. How can i do that..? conn.open(); string result="select name,address,age"; sqlCommand cmnd=new sqlCommand(result); sqlDataAdapter ad=new sqlDataAdapter(result,conn); DataSet ds=new DataSet(); result.Connection=conn; ad.SelectCommand=result; // in here i want to edit (divide age value by 2) before bind data to gridview. ad.fill(ds); GridView1.DataSource=ds; GridView1.DataBind(); conn.close(); i want to divide age value by 2 before bind data to gridview.How can i do that...??? Thank you very much .....
CheeN
A DataSet object is a collection of DataTable objects. You could loop through the table and update the age with something like this:
For Each row As DataRow In ds.Tables(0).Rows row("age") = row("age") / 2 Next
Or you could just do it in the select by changing your select statement to this string:"select name, address, age/2 as age"
Hope this helps. -
Hi All, i want to edit DataSet value before binding to GridView. How can i do that..? conn.open(); string result="select name,address,age"; sqlCommand cmnd=new sqlCommand(result); sqlDataAdapter ad=new sqlDataAdapter(result,conn); DataSet ds=new DataSet(); result.Connection=conn; ad.SelectCommand=result; // in here i want to edit (divide age value by 2) before bind data to gridview. ad.fill(ds); GridView1.DataSource=ds; GridView1.DataBind(); conn.close(); i want to divide age value by 2 before bind data to gridview.How can i do that...??? Thank you very much .....
CheeN
For Each dr As DataRow In ds.Tables(0).Rows
dr("ColumnName") = (dr("ColumnName") / 2)
Next
Where ColumnName is your data column in the DataSet Table.
I don't speak Idiot - please talk slowly and clearly I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury Driven to the arms of Heineken by the wife
-
A DataSet object is a collection of DataTable objects. You could loop through the table and update the age with something like this:
For Each row As DataRow In ds.Tables(0).Rows row("age") = row("age") / 2 Next
Or you could just do it in the select by changing your select statement to this string:"select name, address, age/2 as age"
Hope this helps.