Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用C#和InsertParameters的无时间日期(ASP.NET)_C#_Asp.net_Date - Fatal编程技术网

使用C#和InsertParameters的无时间日期(ASP.NET)

使用C#和InsertParameters的无时间日期(ASP.NET),c#,asp.net,date,C#,Asp.net,Date,我在ASP.NET中使用此C#代码通过“AccessDataSource”在GridView中显示没有时间的日期: 但是,应用程序仍然显示如下日期:dd/MM/yyyy hh:MM:ss 我也试过: string f = DateTime.Now.ToString("dd.MM.yyyy"); string[] v = f.Split(new char[] { ' ' }); AccessDataSource3.InsertParameters["Date birth"].DefaultVal

我在ASP.NET中使用此C#代码通过“AccessDataSource”在GridView中显示没有时间的日期:

但是,应用程序仍然显示如下日期:
dd/MM/yyyy hh:MM:ss

我也试过:

string f = DateTime.Now.ToString("dd.MM.yyyy");
string[] v = f.Split(new char[] { ' ' });

AccessDataSource3.InsertParameters["Date birth"].DefaultValue = ""+v[0];
AccessDataSource3.Insert();
也不行。
也许这些代码不起作用,因为我忘了在其中添加一些内容?

请尝试
ToSortDateString()
方法

var f = DateTime.Now;
string dwt = f.ToShortDateString();

这只会导致
date
17/06/2016

我猜您的数据源将“date birth”字段设置为日期时间类型,当您将字符串指定给它时,将进行转换

您是否尝试过在GridView中设置字段的格式,如下所示:

<asp:boundfield datafield="Date Birth"
        DataFormatString="{0:dd/MM/YYYY}"
        headertext="D.O.B"/>


String.Format(“{0:dd/MM/yyyyy}”,DateTime.Now)
应该可以工作。
Date-birth
是access中的
DateTime
列吗?是的,但是我需要使用C#而不是SQL查询字符串.Format的峰值-我应该这样写代码吗
var f=DateTime.Now
string dwt=f.ToSortDateString()
String.Format(“{0:dd/MM/yyyy}”,f)海报已经删除了字符串的时间部分,并说它仍然不起作用。是的,但我需要一个替代路径来格式化日期,使用C#您需要在数据源中设置字段,使其具有字符串类型,而不是日期时间。否则,您编写的代码如下:DateTime t=(DateTime)(DateTime.Now.ToString(“dd/mm/yyyy”))。
<asp:boundfield datafield="Date Birth"
        DataFormatString="{0:dd/MM/YYYY}"
        headertext="D.O.B"/>