That looks better :)
SqlConnection _con = new SqlConnection(Blah...);
SqlCommand _com = new SqlCommand("Select MAX(companyID) from costumer
where company='1'", _con);
_con.Open();
int _maxcompanyid = (int)_com.ExecuteScalar();
_con.Close();
The ExecuteScalar() method returns the value of the first column of the
first row of the result set as an object and therefore you need to cast it
to the appropriate type depending, in this case, on the declared datatype of
the companyID column.
I have demonstrated the case where it might be an int but you need to modify
that part accordingly.
"David C" <da***@noudata.eswrote in message
news:eX**************@TK2MSFTNGP06.phx.gbl...
No excuse, Select MAX(companyID) from costumer where company='1' for
example...
"Stephany Young" <noone@localhostescribió en el mensaje
news:Oh**************@TK2MSFTNGP06.phx.gbl...
>You can't do a select max(*).
"David C" <da***@noudata.eswrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
>>Hi,
I'm newbie on C#...
Can anybody tell me with a code example how to make a select max(*) and
put it on a variable.
Thnks a lot!
David C.