如何在表格中插入日期 [英] how to insert date into table

查看:83
本文介绍了如何在表格中插入日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将日历控件中的日期插入具有DateTime数据类型的表中以及如何选择日期.

代码是


受保护的void Button1_Click(对象发送者,EventArgs e)
{

如果(IsPostBack)
{
试试
{
con.Open();
SqlCommand cmd =新的SqlCommand("INSERT INTO PurchaseItem VALUES(BILLDATE)(""+ Calendar1.SelectedDate.ToLongDateString()+"''),con);
cmd.ExecuteNonQuery();
}
捕获(SqlException ex)
{
字符串msg =插入错误:";
msg + = ex.Message;
//抛出新的SqlException(msg);

}
终于
{
con.Close();

}
}
}

How to insert date from calendar control into table which has DateTime data type and when I select the date.

code is


protected void Button1_Click(object sender, EventArgs e)
{

if (IsPostBack)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO PurchaseItem VALUES(BILLDATE)(''"+Calendar1.SelectedDate.ToLongDateString()+ "'')", con);
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
// throw new SqlException(msg);

}
finally
{
con.Close();

}
}
}

推荐答案

http://forums.asp. net/t/1616762.aspx/1 [^ ]


"INSERT INTO [dbo.TABLENAME] VALUES (" + Calendar1.SelectedDate.ToLongDateString()+" )"


尝试这一个


这篇关于如何在表格中插入日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆