command更新数据 数据重复而不是覆盖
这是.net写的后台··这一段是更新联系方式的代码,就是一个企业网站的联系方式页面,但每次点提交,数据会添加而不是覆盖,比如code 510990 提交后就变成510990510990 变成重复,请高手知道或者用其他方法·,本人新手,protected void Button1_Click(object sender, EventArgs e)
{
int intUpdataCount;
string sqlconnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(sqlconnstr);
SqlCommand sqlcommand = new SqlCommand();
sqlcommand.Connection = sqlconn;
= "StoredProcedure1";
= CommandType.StoredProcedure;
sqlcommand.Parameters.AddWithValue("@mcid", '1');
sqlcommand.Parameters.AddWithValue("@address", TextBox1.Text);
sqlcommand.Parameters.AddWithValue("@phone", TextBox2.Text);
sqlcommand.Parameters.AddWithValue("@code", TextBox3.Text);
sqlcommand.Parameters.AddWithValue("@qq", TextBox4.Text);
sqlcommand.Parameters.AddWithValue("@email", TextBox5.Text);
try
{
sqlconn.Open();
intUpdataCount = sqlcommand.ExecuteNonQuery();
if (intUpdataCount > 0)
{
Response.Write("<script>alter(\"更新成功\");</script>");
}
}
finally
{
sqlcommand = null;
sqlconn.Close();
sqlconn = null;
}
}
存储过程
ALTER PROCEDURE dbo.StoredProcedure1
(
@mcid bigint,
@address nvarchar(50),
@phone nvarchar(50),
@code nvarchar(50),
@qq nvarchar(50),
@email nvarchar(50)
)
AS
update Contact set address=@address, phone=@phone, code=@code, qq=@qq, email=@email where mcid=@mcid
RETURN