Last post Aug 31, 2014 01:13 PM by arindamnayak
Aug 31, 2014 10:36 AM|ammarhm|LINK
Could anyone please help me out, I am trying to display the sum of a column in an sql table in a Text Box, I am really stuck on this and appreciate any help please
So I have 20 columns and I want to display the sum of the each column (RB1 to RB20) in textboxes (TextBox1 to TextBox20)
Could anyone please help on this?
Should this be done as a stored procedure or within the code behin and how?
Aug 31, 2014 10:48 AM|oned_gk|LINK
Aug 31, 2014 10:52 AM|ammarhm|LINK
Could you please expand on that? Not sure how to use this
Aug 31, 2014 11:12 AM|A2H|LINK
Are you looking for a source code to get the count of a column from database and display it in textbox. if that is the case then you can use the below code
//Variable to hold the value
int TotlaValues = 0;
//Setting the connection string
SqlConnection conn = new SqlConnection(@"Data Source=YourDBServer;Initial Catalog=NORTHWIND;User ID=YourUserID;password=yourPassword;");
//Opening the connection
//Setting the command
SqlCommand sc = new SqlCommand("SELECT SUM(o.EmployeeID) AS TotalCount FROM dbo.Orders o", conn);
//Creating object of reader
//Executing the reader
reader = sc.ExecuteReader();
//Get the Sum of Column from Database
txtTotalCount.Text = reader["TotalCount"].ToString();
Above example fetch the details from Northwind database and you need to change this as per your database.
Aug 31, 2014 01:13 PM|arindamnayak|LINK
If there was SP call to fill initial 20 columns, then we should have a DB call to get those 20 column values, and at that time, we could have make SUM of those 20 columns, instead of one more DB call to get SUM, this just a suggestion over what you proposed.