首页 新闻 赞助 找找看

关于access的问题,(动软的oledb生成代码问题)

0
悬赏园豆:5 [已解决问题] 解决于 2013-10-11 21:58

access数据库是不支持ROW_NUMBER()的,但是我用动软生成器生成出来的数据操作层的代码有这样的一个方法

/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
{
strSql.Append("order by T." + orderby );
}
else
{
strSql.Append("order by T.id desc");
}
strSql.Append(")AS Row, T.* from article_xh T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
return DbHelperOleDb.Query(strSql.ToString());
}

,我在access的sql视图里测试老是错误,提示,语法丢失,操作符错误。

 

怎么写才对呢?

iisp的主页 iisp | 初学一级 | 园豆:81
提问于:2013-10-10 22:50
< >
分享
最佳答案
0
--第一种
select top 10 * from user where id not in (select top 5 id from user order by id )order by id
--第二种
select top 10 * from user
where id >
(
select MAX(id)
from
(
select top 5 Id from user order by id
) a
)
order by id
--这两种都支持access,用的access2013测试的
收获园豆:3
秋壶冰月 | 大侠五级 |园豆:5903 | 2013-10-11 13:45
其他回答(2)
0

当然,这个方法只有在MSSQL2005及以上版本才支持Row_Number

收获园豆:2
空明流光 | 园豆:106 (初学一级) | 2013-10-11 08:06

生成SQL的代码这么简单,如果地方就一处,你重写一下这个函数不就OK了吗,要么就换数据库吧,access,MSSQL,Orace,MySQL都支持SQL,但肯定不能完全通用的。

支持(0) 反对(0) 空明流光 | 园豆:106 (初学一级) | 2013-10-11 08:08
0

换成Access的分页方式呗,top分页。

幻天芒 | 园豆:37175 (高人七级) | 2013-10-11 13:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册