protected void Page_Load(object sender, EventArgs e)
{
string id = Request["id"];
//连接数据库
SqlConnection conn = new SqlConnection("Server=.\\sqlExpress;Integrated Security=False;user id=f;pwd=123;database=db");
conn.Open();
string strSql = "select title,contents from table where id ='" + id+ "'";
SqlCommand com = new SqlCommand(strSql, conn);
SqlDataReader rd;
rd = com.ExecuteReader();
rd.Read();
txtTitle.Text = rd["title"].ToString();
txtContent.Text = rd["contents"].ToString();
conn.Close();
}
protected void btnRewrite_Click(object sender, EventArgs e)
{
string id = Request["id"];
try
{
//连接数据库
SqlConnection conn = new SqlConnection("Server=.\\sqlExpress;Integrated Security=False;user id=f;pwd=123;database=db");
conn.Open();
SqlCommand com = new SqlCommand("update table set title='" + txtTitle.Text.ToString() + "',contents = '" + txtContent.Text.ToString()+ "'where id ="+ id, conn);
com.ExecuteNonQuery();
conn.Close();
Response.Write("");
}
catch
{
Response.Write("");
}
}
代码如上所示
我先绑定数据
然后点击修改以后 把新的数据写入数据库中
本来应该是很简单的过程
而且我用了try catch
而且每次点击修改 都能显示已经操作成功
但是数据库里面的东西一点都没有修改
大家帮我看看问题处在哪里啊
|