2016-10-09 44 views
0

在再次按下文本框中的更新信息並且不更改數據庫中的信息後,在下面的代碼中。請指導我。爲什麼無法更新表單中的數據?

protected void Page_Load(object sender, EventArgs e) 
    { 
     string ConnectionString = ConfigurationManager.ConnectionStrings["tel"].ConnectionString; 

     SqlConnection telConnection = new SqlConnection(ConnectionString); 
     string strSelect = "SELECT * FROM telephon WHERE ID= @ID "; 
     SqlCommand telCommand = new SqlCommand(strSelect,telConnection); 
     telCommand.Parameters.AddWithValue("@ID",Request.QueryString["Code"]); 
     telConnection.Open(); 
     SqlDataReader dr = telCommand.ExecuteReader(); 
     dr.Read(); 
     txtCode.Text = dr["ID"].ToString(); 
     txtName.Text = dr["telName"].ToString(); 
     txtFamily.Text = dr["telFamily"].ToString(); 
     txtOrgan.Text = dr["telOrgan"].ToString(); 
     txtTel1.Text = dr["telTel1"].ToString(); 
     txtTel2.Text = dr["telTel2"].ToString(); 
     txtMob1.Text = dr["telMob1"].ToString(); 
     txtFax.Text = dr["telFax"].ToString(); 
     dr.Close(); 
     telConnection.Close();   
    } 

    protected void btnReg_Click(object sender, EventArgs e) 
    { 
     string ConnectionString = ConfigurationManager.ConnectionStrings["tel"].ConnectionString; 
     SqlConnection telConnection = new SqlConnection(ConnectionString); 
     SqlCommand telCommand = new SqlCommand(); 
     telCommand.Connection = telConnection; 
     telConnection.Open(); 
     telCommand.CommandText = "UPDATE telephon SET [telName]='" + txtName.Text + "' , [telFamily]='" + txtFamily.Text + 
      "',[telOrgan]='" + txtOrgan.Text + "' ,[telTel1]='" + txtTel1.Text + "' ,[telTel2]='" + txtTel2.Text + 
      "',[telMob1]='" + txtMob1.Text + "', [telFax]='" + txtFax.Text + "' WHERE ID=" + Convert.ToInt32(txtCode.Text.Trim()) + ""; 
     telCommand.ExecuteNonQuery(); 
     telConnection.Close(); 
     Response.Redirect("Index.aspx"); 
    } 
+0

我沒有看到一個承諾......如果你不提交就不會更新更改..我不熟悉ASP.NET,但我會懷疑它不會自動提交。 – Rob

回答

相關問題