当我点击按钮更新comments_tbl中的某一行时,它会运行,但数据没有发送,数据库表中的数据保持不变..
我在aspx中有以下html,所以它已经是一种形式: -
<p>Comment<asp:TextBox ID="commenttext" runat="server"></asp:TextBox></p>
我有以下按钮:
<asp:Button ID="Button1" runat="server" Text="Update" OnClick="Button1_Click"/>
按钮后面的代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string connectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
string commenttextupdate = commenttext.Text;
int row = int.Parse(Request.QueryString["commentID"]);
string query = null;
query = "UPDATE comments_tbl SET comment=@comment WHERE ID = @cid";
SqlCommand myCommand = new SqlCommand(query, myConnection);
myCommand.Parameters.AddWithValue("@comment", commenttextupdate);
myCommand.Parameters.AddWithValue("@cid", Request.QueryString["commentID"].ToString());
myCommand.ExecuteNonQuery();
myConnection.Close();
Response.Redirect("../reports.aspx");
}