小编MSW*_*MSW的帖子

SQL Server存储过程正在插入两条记录

我的存储过程应该克隆项目一次,但它创建了两个克隆记录.

我的C#程序有一个调用此方法的按钮.调试只触发一次并返回第二个克隆项目的neweventid

protected void cloneEvent(object sender, EventArgs e)
{
        using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnection"].ConnectionString))
        {
            using (SqlCommand myCommand = new SqlCommand("addRecycleEventAcceptedMaterialsClone"))
            {
                //object returnValue;

                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Connection = myConnection;
                myCommand.Parameters.AddWithValue("@event_id", qsEventId);
                myConnection.Open();
                myCommand.ExecuteNonQuery();

                //returnValue = myCommand.ExecuteScalar();
                NewEventID = (int)myCommand.ExecuteScalar();
            }
        }
        Response.Redirect("eventDetail.aspx?eventid=" + NewEventID);
    }
Run Code Online (Sandbox Code Playgroud)

我检查过没有重复的event_id是主键/标识列

ALTER PROCEDURE [dbo].[addRecycleEventAcceptedMaterialsClone] 
    -- Add the parameters for the stored procedure here
    --Pass in the original event_id
    @event_id int
    --@newEvent_id INT OUTPUT
AS
BEGIN
   -- SET NOCOUNT ON added to prevent extra …
Run Code Online (Sandbox Code Playgroud)

sql sql-server stored-procedures

1
推荐指数
1
解决办法
299
查看次数

标签 统计

sql ×1

sql-server ×1

stored-procedures ×1