用户输入无法保存到数据库

The users input can't save to database

<ItemTemplate>
     <asp:Label ID="lbldescription" runat="server" width="175px"   Text='<%#Eval("description") %>'/>
 </ItemTemplate>
 <EditItemTemplate>
     
     <asp:TextBox ID="txtdescription" runat="server"></asp:TextBox>
 </EditItemTemplate>



protected void gvManage_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string topicID = gvtopic.DataKeys[e.RowIndex].Values["topicID"].ToString();
        TextBox description = (TextBox)gvtopic.Rows[e.RowIndex].FindControl("txtdescription");
        string sql = "Update topic SET description=@description WHERE topicID= @topicID";
        var cmd = new MySqlCommand(sql, con);


        con.Open();

        cmd.Parameters.AddWithValue("@topicID",topicID);
        cmd.Parameters.AddWithValue("@description", description);
       

        cmd.ExecuteNonQuery();
        con.Close();


        gvtopic.EditIndex = -1;
        GVbind();
    }

我正在使用 gridview 来显示描述并让用户编辑和更新它。但是用户的输入(他们在文本框中输入)不会保存到数据库中。无论用户在文本框中键入什么,文本“System.Web.UI.WebControls.TextBox”都将被保存。

代码正在传递一个 TextBox instance as a parameter to the query, not the textbox's contents. AddWithValue“有帮助的”尝试通过调用它的 ToString() 方法将它不理解的任何类型转换为文本。

TextBox 不会重载 ToString(),因此使用默认的 Object.ToString() 方法,returns 类型名称 System.Web.UI.WebControls.TextBox

要传递内容,请使用 TextBox.Text :

cmd.Parameters.AddWithValue("@description", description.Text);