数据库更新语句问题
运行以下代码,出现
System.Data.SqlClient.SqlException: 列名 'daoqi' 无效。我用红字标明了出错的位置。请专家指教!
....
int userid = Convert.ToInt32(Session["userid"]);
string sql2 = "select adddate,LimitYear,loginnum from users where code='" + Number + "'";
DataSet ds2 = bc.getDataSet(sql2); DateTime addTime = Convert.ToDateTime(ds2.Tables[0].Rows[0][0]);
int liyear = Convert.ToInt32(ds2.Tables[0].Rows[0][1]);
DateTime daoqi = Convert.ToDateTime(addTime.AddYears(+liyear));
if (DateTime.Now > daoqi)
{
Response.Redirect("index.aspx");
}
string sqlc2 = "update users set LimitDate= daoqi where userid=" + userid;
//以下这一句是出问题的语句
bc.executesql(sqlc2);
....
public void executesql(string sql)
{
SqlConnection conn = Getconn();
try
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
//在这里抛出异常
throw e;
}
finally
{
conn.Close();
conn.Dispose();
}
}