简体   繁体   中英

Finding value in database by max(ID) and save as a Variable in c#

I've a problem with my program in c# and i hope, you can help me.

My database looks like this:

http://www11.pic-upload.de/08.09.15/czq5yxrrcf24.png

and I want to save the last value of "MaxZyklus" in a variable in c#.

My query to the server is okay, when I write it like this:

select Kabel.maxZyklus 
from Kabel 
where Kabel.kabelTyp = 'PM-K031' 
  and ID = 20; 

select max(ID) from Kabel

but I don't know, how I can do it in one query, and save it in C# as a variable

Hope you can help me.

SELECT YourField FROM YourTable 
WHERE YourKey =(SELECT MAX(YourKey) FROM YourTable )

I found the correct query at

select Kabel.max Zyklus form Kabel where ID = (select max(ID) from Kabel where Kabel.kabelTyp = 'PM-K031');

now saving in a vatiable :) suggestions?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM