将日历中的日期添加到 sql 服务器 2008
adding date from calendar to sql server 2008
我正在使用 asp.net c# 开发一个项目,我从两个日历中获取日期并将它们存储在 SprintsN table、sql server 2008 中指定为日期时间的数据库字段中数据库。但是我遇到了一个例外
异常:
insert into SprintsN (S_Duration, S_Staus, P_ID StartDate,EstEndDate)
values('1week', 'incomplete','5','2015-05-01 12:00:00','2015-05-07
12:00:00');System.Data.SqlClient.SqlException (0x80131904): Incorrect
syntax near 'StartDate'. at
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection, Action`1 wrapCloseInAction) at
代码:
日历事件:
protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
EstDate = Calendar2.SelectedDate.ToString("yyyy-MM-dd hh:mm:ss");
EstDateBox.Text = EstDate;
Calendar2.Visible = false;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
startdate = Calendar1.SelectedDate.ToString("yyyy-MM-dd hh:mm:ss");
SDate.Text = startdate;
Calendar1.Visible = false;
}
Sql 数据库存储处理程序:
String query="";
try {
query = "insert into SprintsN (S_Duration, S_Staus, P_ID StartDate,EstEndDate) values('" + SprintDurBox.Text + "', 'incomplete','" + p_ID + "','"+startdate+"','"+EstDate+"');";
SqlConnection con = new SqlConnection(str);
SqlCommand com = new SqlCommand(query, con);
con.Open();
if (com.ExecuteNonQuery() == 1)
{
SprintStatus.Text = "Sprint Successfully Saved";
}
else
{
SprintStatus.Text = "Sprint not Saved";
}
}
catch (Exception ex)
{
Response.Write(query);
Response.Write(ex.ToString());
}
在您查询的第一部分,您似乎漏掉了一个逗号。
insert into SprintsN (S_Duration, S_Staus, P_ID StartDate,EstEndDate)
应该是:
insert into SprintsN (S_Duration, S_Staus, P_ID, StartDate,EstEndDate)
我正在使用 asp.net c# 开发一个项目,我从两个日历中获取日期并将它们存储在 SprintsN table、sql server 2008 中指定为日期时间的数据库字段中数据库。但是我遇到了一个例外
异常:
insert into SprintsN (S_Duration, S_Staus, P_ID StartDate,EstEndDate) values('1week', 'incomplete','5','2015-05-01 12:00:00','2015-05-07 12:00:00');System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near 'StartDate'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at
代码:
日历事件:
protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
EstDate = Calendar2.SelectedDate.ToString("yyyy-MM-dd hh:mm:ss");
EstDateBox.Text = EstDate;
Calendar2.Visible = false;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
startdate = Calendar1.SelectedDate.ToString("yyyy-MM-dd hh:mm:ss");
SDate.Text = startdate;
Calendar1.Visible = false;
}
Sql 数据库存储处理程序:
String query="";
try {
query = "insert into SprintsN (S_Duration, S_Staus, P_ID StartDate,EstEndDate) values('" + SprintDurBox.Text + "', 'incomplete','" + p_ID + "','"+startdate+"','"+EstDate+"');";
SqlConnection con = new SqlConnection(str);
SqlCommand com = new SqlCommand(query, con);
con.Open();
if (com.ExecuteNonQuery() == 1)
{
SprintStatus.Text = "Sprint Successfully Saved";
}
else
{
SprintStatus.Text = "Sprint not Saved";
}
}
catch (Exception ex)
{
Response.Write(query);
Response.Write(ex.ToString());
}
在您查询的第一部分,您似乎漏掉了一个逗号。
insert into SprintsN (S_Duration, S_Staus, P_ID StartDate,EstEndDate)
应该是:
insert into SprintsN (S_Duration, S_Staus, P_ID, StartDate,EstEndDate)