0

我正在尝试在我的数据库中复制一条记录,我使用了您在下面看到的这段代码,sql 查询在 sql server 中运行良好,但在这里我不知道问题出在哪里......请帮帮我

//Insert new Order
        int newOrderId = 0;
         if (e.CommandName == "Repeat")
         {
             try
             {
                 SqlConnection con = DataAccess.Connection.GetDBConnection();

                 //duplicate the jobs from the old order to the new added order
                 sqlCmd.Parameters.Clear();
                 string com2 = "Insert Into [OrderItems] (orderId, productId, quantity, [length], note, multipleSlip, internalDiameter, " +
                     "wall, machineReCuttingId,winderId, jobNote)  (select @newOrderId, productId, quantity, [length], note, multipleSlip, " +
                     "internalDiameter, wall, machineReCuttingId, winderId, jobNote  FROM OrderItems Where orderId=@oldOrderId)";
                 SqlCommand sqlCmd = new SqlCommand(com2, con);
                 sqlCmd.Parameters.Add("@newOrderId", SqlDbType.Int).Value = newOrderId;
                 //assign the old order Id to the insert parameter @oldOrderId
                 sqlCmd.Parameters.Add("@oldOrderId", SqlDbType.Int).Value = Convert.ToInt32(e.CommandArgument);
                 sqlCmd.ExecuteNonQuery();
                 StatusLabel.Text = "The New Order is" + newOrderId.ToString() + " The Old order ID is: " + e.CommandArgument.ToString();

             }
             catch (Exception ex)
             {
                 Response.Write(ex.ToString());
             }
             OrderGridView.DataSource = ViewDataSource(selectCustomer);
             OrderGridView.DataBind();
            // Response.Redirect("../Orders/AddNewOrder.aspx?customerId=" + selectCustomer + "&" + "orderId=" + newOrderId);

         }

顺便说一下,我测试了 newOrderId 和 oldOrderId 的值,它们都是正确的

4

0 回答 0