网页错误:缺少对象
更新不了数据库中的数据,提示网页上有错误,单击显示缺少对象,但整个语句没报错啊!以下是代码:
protected void btnedit_Click(object sender, EventArgs e)
{
string a = Request.QueryString["id"];
string strsql = "update courseinfo set coursename=@name,establisher=@estab,class=@class,major=@major,teacher=@teacher,uptime=@time,jj=@jj where coursecode=@code";
SqlCommand cm = new SqlCommand(strsql, conn);
try
{
cm.Parameters.Add(new SqlParameter("@code", SqlDbType.VarChar, 50));
cm.Parameters.Add(new SqlParameter("@name", SqlDbType.VarChar, 50));
cm.Parameters.Add(new SqlParameter("@estab", SqlDbType.VarChar, 50));
cm.Parameters.Add(new SqlParameter("@class", SqlDbType.VarChar, 50));
cm.Parameters.Add(new SqlParameter("@major", SqlDbType.VarChar, 50));
cm.Parameters.Add(new SqlParameter("@teacher", SqlDbType.VarChar, 50));
cm.Parameters.Add(new SqlParameter("@time", SqlDbType.DateTime, 8));
cm.Parameters.Add(new SqlParameter("@jj", SqlDbType.VarChar, 100));
cm.Parameters["@code"].Value = a;
cm.Parameters["@name"].Value = txtname.Text;
cm.Parameters["@estab"].Value = txtestab.Text;
cm.Parameters["@class"].Value = txtclass.Text;
cm.Parameters["@major"].Value = txtmajor.Text;
cm.Parameters["@teacher"].Value = txtteacher.Text;
System.DateTime myDate = System.Convert.ToDateTime(txttime.Text);
cm.Parameters["@time"].Value = myDate;
cm.Parameters["@jj"].Value = txtjj.Text;
if (cm.Connection.State == ConnectionState.Closed)
{
cm.Connection.Open();
}
cm.ExecuteNonQuery();
Response.Write("<script>alert('修改成功!')</script>");
}
catch(SqlException ex)
{
Response.Write(ex.Message);
}
cm.Connection .Close();
}
当我单击修改按钮时会弹出“修改成功”,但数据库中的数据没变
请问是为什么啊! --------------------编程问答-------------------- 走断点啊.
或者看看有没有打开连接 --------------------编程问答-------------------- 呵呵,页面提示“缺少对象”是Js错了,和后台程序没有关系
补充:.NET技术 , ASP.NET