I have a asp.net (WebForms) application which has a details view (insert Mode) to add new data.

2 of its fields are datetime type. I have defined the SQL Server database columns as datetime.

Now whenever I'm trying to add date and time it says that it doesn't match the format!

I have seen people having the same problem but unfortunately their solutions didn't work for me. How can i make sure the format matches? Is it possible to display the current datetime as a sample so the user follow it?

Thanks in advance!

DetailsView Code:

<Fields>
          <asp:BoundField DataField="projectName" HeaderText="projectName" SortExpression="projectName" />
          <asp:BoundField DataField="projectType" HeaderText="projectType" SortExpression="projectType" />
          <asp:BoundField DataField="subjectName" HeaderText="subjectName" SortExpression="subjectName" />
          <asp:BoundField DataField="studentID" HeaderText="studentID" SortExpression="studentID" />
          <asp:BoundField DataField="supervisorID" HeaderText="supervisorID" SortExpression="supervisorID" />
          <asp:BoundField DataField="startDate" HeaderText="startDate" SortExpression="startDate" />
          <asp:BoundField DataField="dueDate" HeaderText="dueDate" SortExpression="dueDate" />
          <asp:CommandField ShowInsertButton="True" />
</Fields>
有帮助吗?

解决方案 2

Check Your PC Date format and enter date of same format in due date if you enters the date time dynamically then use like this

DateTime.Now.ToString(yyyy-MM-dd)

here yyyy-MM-dd is my date format enter yours format in this and this is for current date you can use it for the date you desired

其他提示

Its better to use a standard neutral format irrespective of any Regional, Language .. settings.

Use the following format for datetime. If you input your datetime in unseparated or ISO 8601 format shown below, then you should not worry about any configuration/settings:

Unseparated = 'yyyymmdd hh:mm:ss'
ISO 8601    = 'yyyy-mm-ddThh:mm:ss'

The ISO 8601 format has the advantage of being defined in an international standard. And you can pass this format using ToString() method, when handling datetime values:

lblDateTime.Text = (DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"));

This got various advantages as it doesn't needs to check/change settings of Operating System, Database servers ... Continue reading here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top