テキストボックスの更新情報を再度押した後、次のコードで、データベース内の情報を変更しません。私を案内してください。なぜデータをフォームで更新できないのですか?
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");
}
を私はASP.NETに精通していないが、私はそれが自動的にコミットしないだろうと思うだろう。 – Rob