我检查了参数和字段,没有任何错误,但我仍然得到错误..
StringBuilder sb = new StringBuilder();
sb.Append("SELECT u.Name,t.ThreadTitle,t.Date, t.Views,t.Replies,p.Theme,p.Topics,t.PageNumber");
sb.Append("FROM Users AS u");
sb.Append("INNER JOIN Threads AS t ON u.UserID=t.UserID");
sb.Append("INNER JOIN Topics AS p ON p.TopicID=t.TopicID");
sb.Append("WHERE u.UserID=@UserID");
sb.Append("ORDER BY t.Date");
另一个问题是ORDER by date work ..该字段的类型是TimeDate,就像我记得的那样。
答案 0 :(得分:3)
“ASU用户”和“内部加入”之间没有空格。添加空格:
StringBuilder sb = new StringBuilder();
sb.Append("SELECT u.Name,t.ThreadTitle,t.Date, t.Views,t.Replies,p.Theme,p.Topics,t.PageNumber ");
sb.Append("FROM Users AS u ");
sb.Append("INNER JOIN Threads AS t ON u.UserID=t.UserID ");
sb.Append("INNER JOIN Topics AS p ON p.TopicID=t.TopicID ");
sb.Append("WHERE u.UserID=@UserID ");
sb.Append("ORDER BY t.Date");
或者,通过调用AppendLine
而不是Append
来使用换行符。
更好的是,因为这只是一个长字符串,所以请使用逐字字符串:
var sql = @"
SELECT u.Name,t.ThreadTitle,t.Date, t.Views,t.Replies,p.Theme,p.Topics,t.PageNumber
FROM Users AS u
INNER JOIN Threads AS t ON u.UserID=t.UserID
INNER JOIN Topics AS p ON p.TopicID=t.TopicID
WHERE u.UserID=@UserID
ORDER BY t.Date";
答案 1 :(得分:1)
您将所有内容附加到一行。添加空格或使用AppendLine代替附加。
答案 2 :(得分:0)
试试这个:
StringBuilder sb = new StringBuilder();
sb.Append("SELECT u.Name,t.ThreadTitle,t.Date, t.Views,t.Replies,p.Theme,p.Topics,t.PageNumber");
sb.Append(" FROM Users AS u");
sb.Append(" INNER JOIN Threads AS t ON u.UserID=t.UserID");
sb.Append(" INNER JOIN Topics AS p ON p.TopicID=t.TopicID");
sb.Append(" WHERE u.UserID=@UserID");
sb.Append(" ORDER BY t.Date");
是的,orderby应该可以工作。