C# 在Asp.net C中以另一页的形式更新datagrid数据

C# 在Asp.net C中以另一页的形式更新datagrid数据,c#,asp.net,C#,Asp.net,我是asp.net新手,现在我正在测试简单的方法。我想以另一个页面的形式编辑datagrid。这是我的密码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.

我是asp.net新手,现在我正在测试简单的方法。我想以另一个页面的形式编辑datagrid。这是我的密码

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Web.Configuration;  
    using System.Data;  
    using System.Data.SqlClient;  

    public partial class mymembertype : System.Web.UI.Page
    {  
    public static int mem_typeid;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["valueid"] != null)
        {
            mem_typeid = (int)(Session["valueid"]);
            string memtype_name = Convert.ToString(Session["valueName"]);
            string rate = Convert.ToString(Session["rate"]);
            txtmembtype.Text = Convert.ToString(memtype_name);
            txtdscrate.Text = rate;
        }
        }

    protected void Insert_membertype_Click(object sender, EventArgs e)
    {

        funtions fun = new funtions();
        if (mem_typeid == null)
        {

            if (txtmembtype.Text != "")
            {
                if (txtdscrate.Text != "")
                {
                    string membetype = txtmembtype.Text;
                    int dscrate = Convert.ToInt32(txtdscrate.Text);

                    bool chk = fun.Insert_membertype(membetype, dscrate);
                    if (chk)
                        lblInfo.Text = " saving membertype successful";
                    else
                        lblInfo.Text = "Error saving membertype";
                }
            }
        }
        else
        {
            if (txtmembtype.Text != "")
            {
                if (txtdscrate.Text != "")
                {
                    string membetype = txtmembtype.Text;
                    int dscrate = Convert.ToInt32(txtdscrate.Text);

                    bool chk = fun.Update_memberType(mem_typeid, membetype, dscrate);
                    if (chk)
                        lblInfo.Text = " Updating membertype successful";
                    else
                        lblInfo.Text = "Error Updating membertype";
                }
            }

        }


    }
这是我的更新功能

    public bool Update_memberType(int id, string name, int dsc)
        {
        string connectionString =
            WebConfigurationManager.ConnectionStrings["Spa"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(connectionString);
        int memid = id;
        string membtype = name;
        int dsrate = dsc;
        Boolean chk = false;

        try
        {

            myConnection.Open();
            SqlCommand cmd = new SqlCommand("Update_Membtype", myConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@mem_typeId", memid);
            cmd.Parameters.AddWithValue("@membertype_name", membtype);
            cmd.Parameters.AddWithValue("@dsc_rate", dsrate);
            cmd.ExecuteNonQuery();
            chk = true;
        }
        catch (Exception err)
        {
            chk = false;
        }
        return chk;

    }   

当我尝试更新数据时,它不会改变任何东西。变量有其原始值。不会更改为文本框中的新数据。如何修复这些错误。请

你有什么错误吗?另外,您应该在finally块中关闭连接。我收到更新成功消息,但数据未更新。当我调试代码变量时,会使用旧值进行赋值。我认为这是个问题。