我怎么能这样做我根据自己的愿望使用Asp.Net Sql Server无法获取数据 [英] How Can I Do This I Am Not Getting The Data According To My Wish Using Asp.Net Sql Server
问题描述
我想按照日期的降序排序数据
我得到的是
引用:shantanu Date_
15 01/02/2014
12 01/03/2014
16 02/02 / 02 2014
13 02/03/2014
17 03/02/2014
14 03/03/2014
我的代码是
aspx
Quote:< asp :GridView ID =GridView2runat =serverAllowPaging =True
AllowSorting =TrueAutoGenerateColumns =FalseDataSourceID =SqlDataSource1>
<列> < asp:BoundField DataField =shantanuHeaderText =shantanu
SortExpression =shantanu/>
< asp:BoundField DataField =Date_HeaderText =Date_SortExpression =Date_DataFormatString ={0:D}/>
< asp:SqlDataSource ID =SqlDataSource1runat =服务器
ConnectionString =<%$ ConnectionStrings:ritaConnectionString%>
SelectCommand =SELECT * FROM [number11] ORDER BY [Date _]>
i想要的数据应该来了as
shantanu Date_\
15 01/02/2014
16 02/02/2014
17 03/02/2014
12 01/03/2014
13 02/03/2014
14 03/03/2014
请帮助我.....:)
ConnectionStrings:ritaConnectionString%>
SelectCommand = SELECT * FROM [number11] ORDER BY [Date _]>
i想要的数据应该是
shantanu Date_ \
15 01/02/2014
16 02/02/2014
17 03/02/2014
12 01/03/2014
13 02/03/2014
14 03/03/2014
请帮助我...... .. :))
看起来你的Date_列是varc的类型har / nvarchar但是日期,所以它按字母顺序排列你的数据,比如说Dictionary。
所以在SqlDataSource中尝试以下查询,
SELECT * FROM [number11] ORBER BY CONVERT ( DateTime ,Date_, 103 )
试试这个
SELECT * FROM [number11] ORDER BY CONVERT(VARCHAR(12) ),[日期_],103)
i want to sort data in the descending order of date
what i am getting is
Quote:shantanu Date_
15 01/02/2014
12 01/03/2014
16 02/02/2014
13 02/03/2014
17 03/02/2014
14 03/03/2014
my codes are
aspx
Quote:<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<columns> <asp:BoundField DataField="shantanu" HeaderText="shantanu"
SortExpression="shantanu" />
<asp:BoundField DataField="Date_" HeaderText="Date_" SortExpression="Date_" DataFormatString="{0:D}" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ritaConnectionString %>"
SelectCommand="SELECT * FROM [number11] ORDER BY [Date_]">
i want that data should came as
shantanu Date_\
15 01/02/2014
16 02/02/2014
17 03/02/2014
12 01/03/2014
13 02/03/2014
14 03/03/2014
kindly help me.....:)
ConnectionStrings:ritaConnectionString %>"
SelectCommand="SELECT * FROM [number11] ORDER BY [Date_]">
i want that data should came as
shantanu Date_\
15 01/02/2014
16 02/02/2014
17 03/02/2014
12 01/03/2014
13 02/03/2014
14 03/03/2014
kindly help me.....:)
It looks that your Date_ column is type of varchar/nvarchar but date, so it is arranging your data in alphabetical order like say Dictionary.
So try with following query in SqlDataSource,
SELECT * FROM [number11] ORBER BY CONVERT(DateTime, Date_, 103)
(It should 101 instead if I'm not mistaken, try with both of them ;) )
You may find more info here[^].
-KR
try this
SELECT * FROM [number11] ORDER BY CONVERT(VARCHAR(12),[Date_],103)
这篇关于我怎么能这样做我根据自己的愿望使用Asp.Net Sql Server无法获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!