.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to add the values stored in the dataset....

Posted By: Shanthini     Posted Date: July 03, 2009    Points:2   Category :ASP.Net
How to add the values stored in the dataset....

I am having a dataset which stores the values retrived from a table.
Here is the code for taht,

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconnectionstring"].ConnectionString);
SqlCommand command = new SqlCommand("dbo.Utlisation_tab", conn);
command.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds, "dbo.Utlisation_tab");

From this dataset, i am put the values to a gridview using Datatable...

foreach (DataRow dr in ds.Tables[0].Rows)
newRow = tempTable.NewRow();
newRow["col1"] = dr.ItemArray[11].ToString();
newRow["col2"] = dr.ItemArray[0].ToString();
newRow["col3"] = dr.ItemArray[1].ToString();
newRow["col4"] = dr.ItemArray[2].ToString();
newRow["col5"] = dr.ItemArray[3].ToString();
newRow["col6"] = dr.ItemArray[4].ToString();
newRow["col7"] = dr.ItemArray[5].ToString();
newRow["col8"] = dr.ItemArray[6].ToString();
newRow["col9"] = dr.ItemArray[7].ToString();
newRow["col10"] = dr.ItemArray[8].ToString();
newRow["col11"] = dr.ItemArray[9].ToString();
newRow["col12"] = dr.ItemArray[10].ToString();
newRow["col13"] = dr.ItemArray[12].ToString();
//newRow["col14"] = tempTable.Compute("SUM(dr.ItemArray)","").ToString();
//String sum = tempTable.Compute("Sum ( [col1] ) ", "").ToString();


In the above code, col14 is for dispalying total.
So how can a add the values and display it in col14.

Author: Amit Mehra             
Posted Date: July 03, 2009     Points: 5   

Why don't you sort in SQL Query Level? Its best and good in performance also. I strongly recommend in SQL Query level.

Please "Mark As Answer " if this post help you.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend