运行该Sql语句出现“在关键字 'order' 附近有语法错误。” 5
publicDataTableSupesoftPage(stringtableName,stringfields,stringorderFields,stringsqlW...
public DataTable SupesoftPage(string tableName, string fields, string orderFields, string sqlWhere, int pageSize, int pageIndex, out int pageCount, out int recordCount)
{
string commandText = "";
string str2 = "";
int num = pageSize;
DataTable table = null;
try
{
if (sqlWhere == "")
{
sqlWhere = " 1=1";
}
orderFields = orderFields.ToLower();
if (orderFields == "")
{
orderFields = "F_ID";
}
if (orderFields.IndexOf("desc") != -1)
{
str2 = orderFields.Replace("desc", "asc");
}
else
{
str2 = orderFields.Replace("asc", "") + " desc";
}
commandText = "Select Count(*) From " + tableName + " Where " + sqlWhere;
recordCount = DbHelperSQL.Exists1(commandText);
if ((recordCount % pageSize) == 0)
{
pageCount = recordCount / pageSize;
}
else
{
pageCount = (recordCount / pageSize) + 1;
if (pageIndex == pageCount)
{
num = recordCount % pageSize;
}
}
if (pageIndex > pageCount)
{
pageIndex = pageCount;
}
if (pageIndex < 1)
{
pageIndex = 1;
}
table = dataTable(string.Concat(new object[] {
"Select * From (Select top ", num, " * from (select * From (select Top ", pageIndex * pageSize, " ", fields, ",", orderFields.Replace("desc", "").Replace("asc", ""), " From ", tableName, " Where ", sqlWhere, " order by ", orderFields, ") order by ", str2,
")) order by ", orderFields
}));
}
catch (Exception exception)
{
throw exception;
}
return table;
} 展开
{
string commandText = "";
string str2 = "";
int num = pageSize;
DataTable table = null;
try
{
if (sqlWhere == "")
{
sqlWhere = " 1=1";
}
orderFields = orderFields.ToLower();
if (orderFields == "")
{
orderFields = "F_ID";
}
if (orderFields.IndexOf("desc") != -1)
{
str2 = orderFields.Replace("desc", "asc");
}
else
{
str2 = orderFields.Replace("asc", "") + " desc";
}
commandText = "Select Count(*) From " + tableName + " Where " + sqlWhere;
recordCount = DbHelperSQL.Exists1(commandText);
if ((recordCount % pageSize) == 0)
{
pageCount = recordCount / pageSize;
}
else
{
pageCount = (recordCount / pageSize) + 1;
if (pageIndex == pageCount)
{
num = recordCount % pageSize;
}
}
if (pageIndex > pageCount)
{
pageIndex = pageCount;
}
if (pageIndex < 1)
{
pageIndex = 1;
}
table = dataTable(string.Concat(new object[] {
"Select * From (Select top ", num, " * from (select * From (select Top ", pageIndex * pageSize, " ", fields, ",", orderFields.Replace("desc", "").Replace("asc", ""), " From ", tableName, " Where ", sqlWhere, " order by ", orderFields, ") order by ", str2,
")) order by ", orderFields
}));
}
catch (Exception exception)
{
throw exception;
}
return table;
} 展开
4个回答
TableDI
2024-07-18 广告
2024-07-18 广告
在Excel中,字符串匹配函数主要用于查找和定位特定字符串在文本中的位置或进行替换操作。常用的字符串匹配函数包括FIND、SEARCH、SUBSTITUTE和REPLACE等。FIND和SEARCH函数用于查找字符串的位置,而SUBSTIT...
点击进入详情页
本回答由TableDI提供
展开全部
建议将最终的sql文打出来分析,这样看代码何其痛苦。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ACCESS库和sqlserver库在有些函数和关键字定义是不一样的,查一下sql函数说明和关键字说明吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以把sql语句单独存起来,看下sql语句编写是否正确
追问
运行过了出现“'order' 附近有语法错误”,这个错误针对sqlserver数据库,换access数据库就可以运行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询