标题:command更新数据 数据重复而不是覆盖
只看楼主
camenliang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-1-24
 问题点数:0 回复次数:0 
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
搜索更多相关主题的帖子: 联系方式 command 
2013-01-24 21:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-397540-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.155636 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved