为什么不能以表格形式更新数据?

时间:2016-10-09 18:32:20

标签: asp.net

在再次按下文本框中的更新信息后,在以下代码中,不会更改数据库中的信息。请指导我。

    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");
    }

1 个答案:

答案 0 :(得分:0)

您没有提交交易,请参阅此示例,您应该拥有:

{ $match: { something } },
{ $sort: { by date } },
{ $group: { what you wrote } },
{ $group: { a nested $group I tried } }

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.commit(v=vs.110).aspx