本文介绍了如何使用MVC 4在SQL Server中插入日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 当我想将日期插入sql数据库时,它显示错误字符串未被识别为有效的DateTime 。请帮我解答如何使用mvc franework将日期插入sql server。 这是sql表 SELECT TOP 1000 [Id] ,[FirstName] ,[LastName] ,[Email] ,[TelephoneNo] ,[类别] ,[规格] ,[BuyBetweenDatesFrom] ,[BuyBetweenDatesTo] ,[详情] FROM [演示]。[dbo ]。[查询] thsi是CSHTML代码 @ Html.TextBoxFor(x => x.BuyBetweenDatesFrom,new {@placeholder =Select From Date,id =datepickerfrom,@ class =form-control}) @ Html.TextBoxFor(x => x.BuyBetweenDatesTo,new {@placeholder =Select To Date,id =datepicker,@ class =form-control}) 这是日期时间选择器的jquery代码。 < script> $(function(){ $(#datepicker)。datepicker(); }); < /脚本> < script> $(function(){ $(#datepickerfrom)。datepicker(); }); < / script> 这是控制器代码。 public ActionResult ProductInquiry(Enquirya) { 查询查询= new Inquiry(); enquiry.FirstName = Request.Form [ FirstName]; enquiry.LastName = Request.Form [ LastName]; enquiry.Email = Request.Form [ Email]; enquiry.TelephoneNo = Request.Form [ TelephoneNo]; enquiry.Category = Request.Form [ Category]; enquiry.Specifcation = Request.Form [ Specification]; enquiry.BuyBetweenDatesFrom = Convert.ToDateTime(Request.Form [ BuyBetweenDatesFrom]。ToString ()); enquiry.BuyBetweenDatesTo = Convert.ToDateTime(Request.Form [ BuyBetweenDatesTo]。ToString ()); 解决方案 (function(){ ( #datepicker)。datepicker(); }); < / script> < script> (function(){ When I want to insert the date into sql database it shows errorString was not recognized as a valid DateTime.Please help me out how to insert date into sql server by using mvc franework. This is the sql tableSELECT TOP 1000 [Id] ,[FirstName] ,[LastName] ,[Email] ,[TelephoneNo] ,[Category] ,[Specifcation] ,[BuyBetweenDatesFrom] ,[BuyBetweenDatesTo] ,[Details] FROM [Demo].[dbo].[Enquiry]thsi is the CSHTML Code @Html.TextBoxFor(x => x.BuyBetweenDatesFrom, new { @placeholder = "Select From Date ", id = "datepickerfrom", @class = "form-control" }) @Html.TextBoxFor(x => x.BuyBetweenDatesTo, new { @placeholder = "Select To Date ", id = "datepicker", @class = "form-control " })This is the jquery code for datetime picker.<script> $(function () { $("#datepicker").datepicker(); });</script><script> $(function () { $("#datepickerfrom").datepicker(); });</script>This is the Controller code.public ActionResult ProductInquiry(Enquirya) { Enquiry enquiry = new Enquiry(); enquiry.FirstName=Request.Form["FirstName"]; enquiry.LastName = Request.Form["LastName"]; enquiry.Email=Request.Form["Email"]; enquiry.TelephoneNo = Request.Form["TelephoneNo"]; enquiry.Category=Request.Form["Category"]; enquiry.Specifcation=Request.Form["Specification"]; enquiry.BuyBetweenDatesFrom =Convert.ToDateTime(Request.Form["BuyBetweenDatesFrom"].ToString()); enquiry.BuyBetweenDatesTo =Convert.ToDateTime(Request.Form["BuyBetweenDatesTo"].ToString()); 解决方案 (function () {("#datepicker").datepicker(); });</script><script>(function () { 这篇关于如何使用MVC 4在SQL Server中插入日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 16:41