用代码更新的问题(在线等。)
我想用代码实现更新数据库内的资料。写了如下代码,但是总是更新不了数据库里的信息,哪位大哥大姐来帮忙分析下。
protected void Page_Load(object sender, EventArgs e)
{
if (Session[ "Admin "] == null) //若尚未登录则转到登录页
{
Response.Redirect( "../index.aspx ");
}
if (!IsPostBack) //如果不是通过返回打开网页,而是第一次打开该网页
{
Label1.Text = Session[ "Admin "].ToString();
}
string strconn = ConfigurationSettings.AppSettings[ "dsn "];
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string mysql = "select * from login where Username= ' " + Session[ "Admin "].ToString() + " ' ";
SqlCommand cm = new SqlCommand(mysql, cn);
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
TextBox1.Text = dr[ "Name "].ToString();
DropDownList1.Text = dr[ "Sex "].ToString();
TextBox3.Text = dr[ "Telephone "].ToString();
TextBox4.Text = dr[ "Email "].ToString();
TextBox5.Text = dr[ "Adress "].ToString();
dr.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string strconn = ConfigurationSettings.AppSettings[ "dsn "];
SqlConnection cn = new SqlConnection(strconn);
cn.Open();