Role of ExecuteScalar ASP.NET
what is role of ExecuteScalar()?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jan 23, 2012, 12:50 AM
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored
Use the ExecuteScalar method to retrieve a single value (for example, an aggregate value) from a database
Ex:-
Count the total votes and display it in a textbox
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
string str = "select sum(votes)from vote_table";
SqlCommand com = new SqlCommand(str, con);
txt_totalvotes.Text = com.ExecuteScalar().ToString();
con.Close();
Thanks
Chetan koralliPosted Jan 23, 2012, 12:14 AM