由网友(古城白衣少年殇彡)分享简介:我要如何转换成字符串在文本框中DD / MM / YYYY日期格式,我的意思是财产以后这样的:日期D =日期(textBox.Text);我想用它作为SQL参数为日期数据类型如下:command.Parameters.Add(新NpgsqlParameter(V5,NpgsqlDbType.Date));解决方案 您可...
我要如何转换成字符串在文本框中DD / MM / YYYY日期格式,我的意思是财产以后这样的:
日期D =日期(textBox.Text);
我想用它作为SQL参数为日期
数据类型如下:
command.Parameters.Add(新NpgsqlParameter(V5,NpgsqlDbType.Date));
解决方案
您可以使用的 TryParseExact()
方式:
//使用System.Globalization;
日期时间指明MyDate;
如果(DateTime.TryParseExact(textBox.Text,DD / MM / YYYY,CultureInfo.InvariantCulture,DateTimeStyle.None,出指明MyDate)){
//做一点事
}
How do I convert a string in a text box to dd/mm/yyyy date form, I mean somthing like:
Date d = Date(textBox.Text);
I would like to use it as a parameter in SQL as Date
data-type as following:
command.Parameters.Add( new NpgsqlParameter("v5", NpgsqlDbType.Date));
解决方案
You could use the TryParseExact()
method:
//using System.Globalization;
DateTime myDate;
if(DateTime.TryParseExact(textBox.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyle.None, out myDate)){
//do something
}
相关推荐
最新文章