我怎么能这样做我根据自己的愿望使用Asp.Net Sql Server无法获取数据 [英] How Can I Do This I Am Not Getting The Data According To My Wish Using Asp.Net Sql Server

查看:81
本文介绍了我怎么能这样做我根据自己的愿望使用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 



如果我没弄错的话应该101,试试两个;) )



您可以找到更多信息 here [ ^ ]。



-KR


试试这个

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆