如何在asp.net c中使用datetime数据类型在sql server中保存出生日期# [英] how can save date of birth in sql server using datetime datatype with asp.net c#
本文介绍了如何在asp.net c中使用datetime数据类型在sql server中保存出生日期#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的一些编码,因此一些错误字符串无效日期时间
here is my some coding which so some error string was not valid date time
protected void btnsave_Click(object sender, EventArgs e)
{
string dfs = "26-06-1986";
DateTime dd = new DateTime();
dd = Convert.ToDateTime(dfs);
SqlCommand cmd = new SqlCommand("insert into dk values('"
+ TextBox1.Text+ "','" + TextBox2.Text+ "')", con);
con.Open();
cmd.ExecuteNonQuery();
}
}
}
推荐答案
您可以从这里 [ ^ ]。
可能在下面的代码行中,它不是一个有效的日期时间格式:
You can read more about Convert.ToDateTime from here[^].
Probably it's not a valid datetime format what you are using in the following line of code:
string dfs = "26-06-1986";
试试这个例子:
Try this for example:
string dfs = "26/06/1986";
这是你的日期,如果你不能用短划线和默认的日期模式:
Here's your date, if you can't make it out of the dashes and into the default date patterns:
string dfs = "26-06-1986";
DateTime dd = new DateTime(Convert.ToInt32(dfs.Substring(6)), Convert.ToInt32(dfs.Substring(3, 2)), Convert.ToInt32(dfs.Substring(0, 2)));
这篇关于如何在asp.net c中使用datetime数据类型在sql server中保存出生日期#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文