我是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;
}
当我尝试更新数据时,它不会改变任何内容。变量具有其原始值。不会更改为文本框中的新数据。我该如何解决这些错误。请...