Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Without using dbdatareader, could you please give me a solution to extract some value in the result from executing a select command, for example:
C#
mysqlcommand.CommandText = "Select max(Mark) from MarkSummary";
mysqlcommand.ExecuteNonQuery()

The value I want to extract here is max of the column Mark as I said without using SqlDataReader or IDataReader or even loading the data into a DataTable before extracting from that or even creating a stored function. I want to deal it primitively and purely with Select command.
Thank you so much!
Posted
Updated 10-Sep-11 9:34am
v2

1 solution

use ExecuteScalar() e.g.
C#
object max = mysqlcommand.ExecuteScalar()
 
Share this answer
 
Comments
[no name] 10-Sep-11 16:04pm    
Just a trick but it's exactly what I want.
That ExecuteScalar in fact works in a similiar way that ExecuteReader works, I have learned that ExecuteScalar gets only the value at the first column of the first row while ExecuteReader gets all the result.
I wonder if we have any other ways to solve this?
I voted you with 5s but please wait until I accept your answer. Just for I want more others to get in here and try thinking out some other solution. I don't mean yours is not the best, in fact it is the best, I think, but I like to solve problems in as many ways as possible.
Thank you so much!
Simon Bang Terkildsen 10-Sep-11 16:53pm    
That's completely ok, I admire your desire to have multiple solutions to a problem in your tool belt.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900