Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

System.Data.SqlClient.SqlException: Procedure or function 'UpdateSHCInvoice' expects parameter '@Qty', which was not supplied

$
0
0

Here is my code behind for the web form:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;



namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void MasterData_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {

            using (SqlConnection con = new SqlConnection("server=(local);database=InvoiceSHC;Trusted_Connection=Yes"))
            {

                // Get the UserId of the logged in user
 
                string UserName = "";
                if (HttpContext.Current.User.Identity.IsAuthenticated)
               {
                   UserName = HttpContext.Current.User.Identity.Name.ToString();
               }
                else
               {
                   UserName = "UnauthenticatedUser";
               }
                
                
                string Timestamp = DateTime.Now.ToString();
                //Not sure why you need a SqlDataAdapter unused here.
                //SqlDataAdapter DA = new SqlDataAdapter("UpdateSHCInvoice", con);
                SqlCommand cmd = new SqlCommand("UpdateSHCInvoice", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Ref", dlRef.SelectedItem.Value);
                cmd.Parameters.AddWithValue("@PhaseName", dlPhase.SelectedItem.Value);
                cmd.Parameters.AddWithValue("@PageType", dlPageType.SelectedItem.Value);
                cmd.Parameters.AddWithValue("@Page", tbPage.Text);
                cmd.Parameters.AddWithValue("@Percent", dlPercent.SelectedItem.Value);
                cmd.Parameters.AddWithValue("@ChngType", dlChngType.SelectedItem.Value);
                cmd.Parameters.AddWithValue("@UserName", UserName);
                cmd.Parameters.AddWithValue("@Timestamp",Timestamp);
                cmd.Parameters.AddWithValue("@Qty", tbQty.Text);
                con.Open();
                cmd.ExecuteNonQuery();

                GridView1.DataBind();

            }

        
        
        }

        
    }
}

and here is my stored procedure that is called:

USE [InvoiceSHC]
GO
/****** Object:  StoredProcedure [dbo].[UpdateSHCInvoice]    Script Date: 04/19/2013 07:23:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date,,>
-- Description:    <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[UpdateSHCInvoice]
    -- Add the parameters for the stored procedure here
    (@Ref nvarchar(50),
    @PhaseName nvarchar(50),
    @PageType nvarchar(50),
    @Page nvarchar(50),
    @Percent nvarchar(50),
    @ChngType nvarchar(50),
    @UserName nvarchar(100),
    @Timestamp datetime,
    @Qty int)
    
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    insert into MasterData2 ([Ad],[Phase],[Page Type] , [Page], [Percent] , [Change Type],[UserName], [Timestamp] , [Qty])
                    values(@Ref, @PhaseName , @PageType , @Page , @Percent ,@ChngType, @UserName, @Timestamp, @Qty );
    
     update MasterData2
        set [page_equivalent]  =
        Case
            When [Page] like '[0-9][A-Z]' then left([Page],1)+((ASCII(convert(varchar,(RIGHT([Page],1))))-64)*.01)
            When [Page] like '[0-9][0-9][A-Z]' then left([Page],2)+((ASCII(convert(varchar,(RIGHT([Page],1))))-64)*.01)
            When[Page] like '[0-9]-%' then LEFT([Page],1)+(cast(RIGHT([page],2)as int)*.01)+.26
            When[Page] like '[0-9][0-9]-%' then LEFT([Page],2)+(cast(RIGHT([page],2)as int)*.01)+.26
            When [Page] like '[0-9]' then LEFT([Page],1)
            When [Page] like '[0-9][0-9]' then LEFT([Page],2)
            When [Page] like '[0-9][A-Z]-%' then left([Page],1)+((ASCII(convert(varchar,(substring([Page],2,1))))-64)*.01)+ (cast(RIGHT([page],2)as int)*.001)
            When [Page] like '[0-9][0-9][A-Z]-%' then left([Page],2)+((ASCII(convert(varchar,(substring([Page],3,1))))-64)*.01)+ (cast(RIGHT([page],2)as int)*.001)
        end

END

The process was working until I added the text box tbQty.  The value is necessary for reporting purposes.  I need to be able to enter either a 1 or -1.  The table has a primary key cluster for all of the fields except for the UserName and Timestamp.  I cannot set the value of the field qty = null which is what others have used to get around this problem.  The reason is the qty is a primary key. 

Does anyone have an insight as to why I am unable to get this to work?


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>