本文介绍了日历System.Globalization.GregorianCalendar中不支持字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在日期落在12点之后,我在检索日期时遇到了问题,例如:如果我从calander扩展器中单击:2013/2/7到2013年7月19日,会因为这个错误而把它扔给我:日历System.Globalization.GregorianCalendar中不支持该字符串表示的DateTime.
i am having problem with my retrieving of date after the date fall after 12. for example : if i click from the calander extender: 2/7/2013 to 19/july/2013 , is will throw it me with this error : The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.
这是我的代码.
var format = "MM/dd/yyyy";
DateTime one = DateTime.ParseExact(startdate, format, CultureInfo.InvariantCulture);
DateTime two = DateTime.ParseExact(enddate, format, CultureInfo.InvariantCulture);
if (two >= one)
{
SqlConnection conn = new SqlConnection("Data Source=""catalog="";Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT Name,CLass, NRIC, StallNo, AmountSpent ,TimeDate=convert(nvarchar,timedate,103) FROM StudentTransactions WHERE TimeDate BETWEEN '" + one + "' AND '" + two + "'", conn);
SqlDataReader reader = cmd.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataSourceID = null;
GridView1.Visible = true;
GridView1.DataBind();
conn.Close();
}
推荐答案
尝试一下
select CONVERT(varchar,<datecol>,103) --- and will return as dd/mm/yyyy
where convert(date,<datecol>) between '' and ''
这篇关于日历System.Globalization.GregorianCalendar中不支持字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!