asp.net更新指定记录的方法

2019-05-23 07:32:21于海丽

        <asp:TextBox ID="TxtNum" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Label ID="Label5" runat="server" Font-Size="Smaller" Text="商品单价:"></asp:Label>
        <asp:TextBox ID="TxtPrice" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td colspan="2" style="width: 496px">
                         <asp:Button ID="BtnUpdate" runat="server" OnClick="BtnUpdate_Click" Text="更新" Width="55px" /></td>
                </tr>
            </table>
        </div>
    </form>
由上面页面提交过来的数据我们接受然后利用sql执行更新数据库
View Code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)//首次执行页面时
        {
            GridViewBind();//绑定自定义方法GridViewBind
            if (Request.QueryString["商品编号"] != null)//判断,如果可以获取到id的值,则执行以下操作
            {
                SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);