如何将这些帖子设置为降序asp.net c#

时间:2014-12-18 17:02:24

标签: c# asp.net facebook

我正在创建一个社交网络网站作为Facebook,但该网站有一些摆出状态的错误,我使用以下代码发布状态。我在page_Load事件和发布按钮

上调用了此方法
 private DataSet GetData()
{

    string CS=ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString;
    using (SqlConnection con = new SqlConnection(CS))
    {
        SqlDataAdapter da = new SqlDataAdapter("Select * from PhotoStatusProfile WHERE Email = '" + Session["Email"].ToString() +"'",con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;


    }

}

这是html代码

<asp:Repeater runat="server" ID="Repeater1">
 <ItemTemplate>

     <div class="yourDivClass" style="border-top: thin none #BBCEB3; border-bottom: thin none #BBCEB3; padding: 10px; height: 121px; width: 548px; margin-top: 10px; right: 10px; left: 10px; border-left-width: thin; margin-left: 15px; background-color: #e9eaee; border-left-color: #BBCEB3; border-right-color: #BBCEB3;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <br />
                    <div style="width: 58px; height: 62px">
                    <asp:Image ID="Image1" runat="server" Height="59px" ImageAlign="Top" ImageUrl="~/Profile/Image/supun_Profilemini.jpg" Width="55px" />
                        </div>
                    <div style="width: 307px; height: 21px; margin-left: 65px; margin-top: -60px">
                        <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Names="Arial" ForeColor="#000066" ><%#Eval("name") %> </asp:Label>
                    </div>
                    <div style="height: 22px; width: 461px; margin-left: 78px; margin-top: 11px">&nbsp;<asp:Label ID="Label8" runat="server"><%#Eval("Status") %></asp:Label>
                   <br><br>
                         </div>
                    &nbsp;</div>
 </ItemTemplate>

发布按钮cs代码

   SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
        conn.Open();
        try
        {



            string inserQuery = "insert into PhotoStatusProfile(Name,Status,Email,Date) values (@Name,@Status,@e,@CreatedAt)";
            SqlCommand commm = new SqlCommand(inserQuery, conn);
            commm.Parameters.AddWithValue("@Name", ProfileName.Text);
            commm.Parameters.AddWithValue("@Status",TextBox1.Text);
            commm.Parameters.AddWithValue("@e", Label1.Text);
            commm.Parameters.AddWithValue("@CreatedAt", DateTime.Now);


            commm.ExecuteNonQuery(); 


            Label1.Text = Session["Email"].ToString();



        }

但在我发布一些状态后,我遇到了一些错误。

在这个网站上,my new post displayed on bottom and oldest one on top但我想要新帖子到顶部,其他人逐渐从上到下,(考虑时间按降序排列)

给我一​​个建议,让这个代码按降序设置这些

SqlDataAdapter da = new SqlDataAdapter("Select * from PhotoStatusProfile WHERE Email = '" + Session["Email"].ToString() + "'", con);

由于

1 个答案:

答案 0 :(得分:0)

SqlDataAdapter da = new SqlDataAdapter(“Select * from PhotoStatusProfile WHERE Email ='”+ Session [“Email”]。ToString()+“'order by Date desc”,con);