SQL语句失败

时间:2011-07-02 17:31:27

标签: c# asp.net sql-server sql-order-by

我用这句话:

  SELECT ThreadsID
    FROM Threads 
ORDER BY ThreadsID DESC

为什么sql语句无法返回我期望的内容?出于某种原因,它会在id = 32id = 52之间放置一条id = 53的记录:

threadid
---------
...
53
32  -- <-- huh?!
52

连接字符串:

    <add name="modelConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename='D:\Documents and Settings\Dima\My Documents\Visual Studio 2010\WebSites\WebSite10\App_Data\ASPNETDB.MDF';Integrated Security=True;User Instance=True;Trusted_Connection=Yes;"
  providerName="System.Data.SqlClient" /

我有其他影响列表的信息:

    StringBuilder sb = new StringBuilder();
    sb.Append("SELECT u.Name,t.ThreadTitle,t.Date, t.Views,t.Replies,p.Theme,p.Topics,t.PageNumber, t.ThreadsID");
    sb.Append("  FROM Threads AS t");
    sb.Append( " INNER JOIN Users AS u ON u.UsersID=t.UsersID");
    sb.Append( " INNER JOIN Topics AS p ON p.TopicsID=t.TopicsID");
    sb.Append(" WHERE t.ThreadsID=@ThreadsID");

@ ThreadsID..goes到第二个查询...但它不影响事物的顺序..在这两个单独的sql命令执行后我得到了我得到的奇怪结果

1 个答案:

答案 0 :(得分:0)

可能是因为Id不是数字类型。你的桌子上有什么类型的数据?