第 1 行: 'PublishArticle' 附近有语法错误。请各位帮小弟看看,谢谢各位了
本帖最后由 kangshaofei 于 2013-09-24 10:20:17 编辑 如下错误提示:,这个是分页取数据,但是出现错误,我实在看不出,请大家帮帮我,谢谢了
下面是我部分代码:
web层代码:
int RecordCount = 0;
int PageSize = 10;//每页显示的条数
int PageIndex = 1;//当前页数
public DataTable GetArticle(int userId)
{
Article articleBll = new Article();
string strUrl = string.Format("BlogDefault.aspx?userId={0}&", userId);
DataTable dt = articleBll.StructureArticleListDefault(userId, PageSize, PageIndex, out RecordCount);
return dt;
}
BLL代码:
/// <summary>
/// 构造首页博文列表
/// </summary>
/// <param name="userId"></param>
/// <param name="pageSize"></param>
/// <param name="pageIndex"></param>
/// <param name="recordCount"></param>
/// <returns></returns>
public DataTable StructureArticleListDefault(int userId,int pageSize,int pageIndex,out int recordCount)
{
string strWhere = "PublishArticle.IsShow = 1 and PublishArticle.ArticleFrom < 2 and ";
strWhere += "PublishArticle.UserId = "+userId;
DataTable dt = dal.GetDefaultArticleData(pageSize, pageIndex, out recordCount,strWhere);
return dt;
}
DAL代码:
/// <summary>
/// 分页获取首页博文数据表
/// </summary>
/// <param name="PageSize"></param>
/// <param name="PageIndex"></param>
/// <param name="RecordCount"></param>
/// <param name="strWhere"></param>
public DataTable GetDefaultArticleData(int PageSize, int PageIndex, out int RecordCount,string strWhere)
{
string tabName = "Tab_Article as Article inner join Tab_PublishArticle as PublishArticle on Article.ArticleId = PublishArticle.ArticleId";
string fieldName = "PublishArticle.RecordId,Article.PublisherId, PublishArticle.ArticleId,";
fieldName += "PublishArticle.ArticleFrom,";
fieldName += "PublishArticle.ReadCount, PublishArticle.CollectionTime,";
fieldName += "Article.ArticleTitle, Article.ArticleContent, Article.IsContainPic,";
fieldName += "Article.ArticleTag, Article.ArticleTypeName, Article.SetComment,Article.SetArticleReprint";
string fieldSort = "PublishArticle.CollectionTime";
SqlParameter[] parameters = new SqlParameter[] {
new SqlParameter("@tblName", SqlDbType.NVarChar, 300),
new SqlParameter("@fldName", SqlDbType.NVarChar, 800),
new SqlParameter("@pageSize", SqlDbType.Int),
new SqlParameter("@page", SqlDbType.Int),
new SqlParameter("@pageCount", SqlDbType.Int),
new SqlParameter("@Counts", SqlDbType.Int),
new SqlParameter("@fldSort", SqlDbType.NVarChar, 200),
new SqlParameter("@Sort", SqlDbType.Bit),
new SqlParameter("@strCondition", SqlDbType.NVarChar, 0x3e8),
new SqlParameter("@ID", SqlDbType.NVarChar, 150),
new SqlParameter("@Dist", SqlDbType.Bit)
};
parameters[0].Value = tabName;
parameters[1].Value = fieldName;
parameters[2].Value = PageSize;
parameters[3].Value = PageIndex;
parameters[4].Direction = ParameterDirection.Output;
parameters[5].Direction = ParameterDirection.Output;
parameters[6].Value = fieldSort;
parameters[7].Value = true;
parameters[8].Value = strWhere;
parameters[9].Value = "Article.ArticleId";
parameters[10].Value = false;
using (SqlConnection Conn = new SqlConnection(SqlHelper.connectionString))
{
DataSet ds = SqlHelper.ExecuteDataset(Conn, CommandType.StoredProcedure, "proc_ListPage", parameters);
RecordCount = Convert.ToInt32(parameters[5].Value);
DataTable dt = new DataTable();
if (ds.Tables.Count > 0)
{
dt = ds.Tables[0];
}
Conn.Close();
return dt;
}
}
[解决办法]
打断点调试吧 肯定是sql拼接有问题
[解决办法]
那就去调试存储过程吧 用print把拼接的sql语句打出来
[解决办法]
拼出来的SQL语句有问题
把SQL放查询分析器里执行看看
估计是少空格了
[解决办法]
在查询分析器里执行你的存储过程 比如:exec 存储过程名 '参数' 按F11就能调试了
[解决办法]
把你最后生成的SQL 发出来
[解决办法]
测试生成的sql语句