Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to take maximum value from a column of ms acess data base

i used the following code:

dr2=obj.SelCommand("select max([ID]) from tbl_registercomplaints");

int n = Convert.ToInt32(dr2.Read());

here dr2 is an object of datareader and obj is an object of class which includes definition for selection command.

in the above case,its returns only one value and its '1'
every time the value of n is 1.

the query analyser shows the correct result.

please help me to find a solutions for this.


Kishore R
Gis Solutions
www.uniquewebdeveloper.co.cc
Posted

1 solution

IDataReader.Read() returns a bool which is true if a row was read.

You need to get the value of the first field in that row. Here is one way to do that:

C#
int maxId = dr2.GetInt32( 0 );


Nick
 
Share this answer
 

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