开发者

last record from database [closed]

Closed. This question needs debugging details. It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.

Closed 7 years ago.

Improve this question 开发者_如何学Python

Get the last record from a Microsoft SQL database table using ASP.net (VB) onto a web form.


I'm assuming he's trying to retrieve the last inserted record. As Ariel pointed out, the question is rather ambiguous.

SELECT TOP 1 * FROM Table ORDER BY ID DESC

If you have an identity column called ID, this is easiest. If you don't have an identity PK column for example a GUID you wont be able to do this.


Here is a basic solution:

var order = (from i in db.orders
             where i.costumer_id.ToString() == Session["costumer_id"]
             orderby i.order_id descending
             select i).Take(1).SingleOrDefault();


You need to be more specific with actually putting it onto a web form, but the SQL to get the last record is:

SELECT * 
FROM    TABLE_NAME
WHERE   ID = (SELECT MAX(ID)  FROM TABLE_NAME)

Where ID is your ID and TABLE_NAME is your table name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜