一、双TOP法高效率的Access分页的SQL语句,语法格式:
SELECT * FROM
(SELECT TOP "&pagesize&" * FROM
(SELECT TOP "&page*pagesize&" 字段 FROM 表 ORDER BY id DESC)
ORDER BY id)
ORDER BY id DESC
二、扩展带条件的
SELECT * FROM
(SELECT TOP 2 * FROM
(SELECT TOP 2 id FROM SoftwareAuthorizeInfo ORDER BY id DESC)
ORDER BY id)
where id=3 ORDER BY id DESC
上面是错误
SELECT * FROM
(SELECT TOP 2 * FROM
(SELECT TOP 2 id FROM SoftwareAuthorizeInfo where id=3 ORDER BY id DESC)
ORDER BY id)
ORDER BY id DESC
这里还要注意 C#使用的Access引擎和Office使用引擎好像不一样 where = " where ProjectName LIKE ‘" + search.Text + "’ "; Access可以,但是C# 执行不了
所以 要加
if (search.Text != "")
{
where = " where ProjectName LIKE '%" + search.Text + "%' ";
}
三、倒叙查询的
SELECT * FROM
(SELECT TOP 2 * FROM
(SELECT TOP 2 id FROM SoftwareAuthorizeInfo ORDER BY id DESC)
ORDER BY id) ORDER BY id DESC
四、正序(只需要更最后一个 为ASC)
SELECT * FROM
(SELECT TOP 2 * FROM
(SELECT TOP 2 id FROM SoftwareAuthorizeInfo ORDER BY id DESC)
ORDER BY id) ORDER BY id ASC