首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

求解释sql基础~该怎么解决

2012-11-09 
求解释sql基础~public DataTable GetList(int top){StringBuilder strSql new StringBuilder()string a

求解释sql基础~
public DataTable GetList(int top)
  {
  StringBuilder strSql = new StringBuilder();
  string addsql = "top "+top;
  if (top <= 0)
  {
  addsql = "";
  }

  strSql.Append("select " + addsql + " a.ID,a.Author,a.TypeId,a.[Subject],a.[Content],a.[Count],a.date,b.Type ");
  strSql.Append(" FROM Article a join [type] b on a.TypeId = b.ID order by a.ID desc");
  return SQLHelper.ExecuteTable(strSql.ToString());
  }


addSql为什么是一个字段,表示什么意思?a.和b.又是什么?from大小写没关系?数据库中的content和subject都没中括号的,而在代码中加了中括号?count在数据库中加了中括号我理解~

[解决办法]
这是拼SQL语句,假如参数Int top=3,则SQL语句为:

SQL code
select top 3 a.ID,a.Author,a.TypeId,a.[Subject],a.[Content],a.[Count],a.date,b.Type FROM Article a join [type] b on a.TypeId = b.ID order by a.ID desc 

热点排行