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在数据库中加了中括号我理解~
{
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在数据库中加了中括号我理解~
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
top 3就是取数据的前3条数据;
a就是Article表(相当于简写),
select a.Subject from FROM Article a等同于select Article.Subject from FROM Article,b就是type表了;
SQl语句是不区人大小写的;
加中括号是为了避免与数据库关键字冲突
a是Article 别名
[type]type是关键词
有些字段可能是SQL里面的保留字,但是你又用了它做字段名 比如 count,那么用[count]可以避免这个问题