如何结合分娩日期并加入数据库 [英] How concatinate splited date of birth and add into database
本文介绍了如何结合分娩日期并加入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Html.DropDownListFor(model => model.Day, listItems, "Day",new {@Id="ddlDay", style = "width: 70px;" })
@Html.DropDownListFor(model=>model.Month, listItemsMonth,"Month",new{@Id="ddlMonth",style = "width: 90px;"})
@Html.DropDownList("Years", new SelectList(ViewBag.Years as System.Collections.IEnumerable, Model.Year), new {@Id="ddlYear",style = "width: 70px;" })
这是我的模型
this is my model
public DateTime Day { get; set; }
public DateTime Month { get; set; }
public DateTime Year { get; set; }
public DateTime DateofBirth { get; set; }
这是我的控制器
this my controller
public ActionResult AddUsers()
{
}
我的db我的列为Datetime
My db i have column as Datetime
推荐答案
您可以将所有值连接成一个字符串(即db中的varchar)并将其转换为datetime。
Ex:2014-08-01 05 :21:58.340这是一个字符串。
转换:
You can concatenate all the values into a single string (i.e varchar in db) and convert that to datetime.
Ex: "2014-08-01 05:21:58.340" which is a string.
Conversion:
Convert(datetime,'2014-08-01 05:21:58.340')
一种简单的方法是创建一个新的DateTime
,其构造函数包含日,月和作为参数的年份。请参阅: DateTime构造函数(Int32,Int32,Int32) [< a href =http://msdn.microsoft.com/en-us/library/xcfzdy4x(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]
之后你应该创建一个SqlCommand,准备参数并执行语句。看看 SqlCommand.ExecuteNonQuery [ ^ ]
An easy way is to create a newDateTime
with a constructor that has day, month and year as paramers. See: DateTime Constructor (Int32, Int32, Int32)[^]
After that you should create a SqlCommand, prepare the parameters and execute the statement. Have a look at SqlCommand.ExecuteNonQuery[^]
这篇关于如何结合分娩日期并加入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文