473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SELECT MAX(*) TO A VAR

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.
Dec 1 '06 #1
3 2479
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.

Dec 1 '06 #2
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.


Dec 1 '06 #3
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.



Dec 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tanamon | last post by:
Hello All, I am a MySQL newbie trying to write a query that selects file_name records possessing the highest numbered version for that unique file_name. I show sample data and two trial queries...
4
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | ...
1
by: alexqa2003 | last post by:
got a table with (class, name, exam, score) fields. To find max(score) for exam that starts with letter 'm' grouped by class and name,did: select max(score) from #temp where exam like 'm%'...
2
by: Eric | last post by:
please help to select these rows from these tables my tables are table1 table1Id groupId table2id price 1 1 1 10 2 1 3 1000 3 1 ...
3
by: Ker | last post by:
I have a query that works great. It gives me the min for multiple fields. Within this query, I also need to get the max of some fields too. I currently have output of Date Name ...
7
by: Milos Prudek | last post by:
I need to insert a value = max(value)+1, where max is a select limited by a 'where' clause. Like this: INSERT INTO table (idthread, idsection,txt) VALUES ( (SELECT max(idthread)+1 FROM table...
4
by: Sandy | last post by:
Hi, I have a table A (ID, time,...) first I want to select rows with max value of time. Then from these rows I want the row with max ID value. i am doing the following but its giving me the...
3
by: otac0n | last post by:
How can I select the maximum value from a field, but make sure that the value i want stays greater than a cetrain value? I currently have this: SELECT A.rating, B.rating,...
7
by: Aaron Lawrence | last post by:
Hello all. Is there a simpler way to write something like this: select column_a from table where column_b = ( select max( column_b ) from table ) ie. find the row where column_b is at it's...
3
by: ncsthbell | last post by:
I am trying to run a query in access using the 'max' function. For example, I have many rows of data, one for each state and each state has a column for 'Miles'. I want to get the highest number of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.