[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

Procedure or function 'UpdatePHICounter' expects parameter '@ID', which was not supplied.

I am trying to update a record in a table where I thought I was supplying the one variable that it needs.  Can someone point out what I am blind to?

Here is my SQL Procedure:
------------------------------------------------

USE [12312]
GO
/****** Object:  StoredProcedure [dbo].[UpdatePHICounter]    Script Date: 11/06/2008 23:27:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Proc [dbo].[UpdatePHICounter]

@ID decimal


AS
BEGIN
SET NOCOUNT ON

UPDATE [DRRPHICntr]

SET ID = @ID


SET NOCOUNT OFF
End


Here is my C# Code:
-------------------------------------------------------------------------------------------------

///  ---------------   Write Updated Counter Back to Database
     

            SqlConnection UpdateNewPHICntrConn;
            UpdateNewPHICntrConn = new SqlConnection();
            UpdateNewPHICntrConn.ConnectionString = ConfigurationManager.ConnectionStrings["HIPAAv2ConnectionString"].ConnectionString;
            SqlCommand Updcmd;
            UpdateNewPHICntrConn.Open();

            Updcmd = new SqlCommand("UpdatePHICounter", UpdateNewPHICntrConn);
            Updcmd.CommandType = CommandType.StoredProcedure;
            id = Convert.ToDecimal(Session.Contents["id"].ToString());
            Updcmd.Parameters.Add("@ID", SqlDbType.Decimal).Value = id;
 
            Updcmd.Parameters.Clear();

           

            // Write Updated Counter Data
            Updcmd.ExecuteNonQuery();-----------------------------------Error Occurs Here

            if (UpdateNewPHICntrConn != null)
            {
                UpdateNewPHICntrConn.Close();
            }
0
kwh3856
Asked:
kwh3856
  • 3
  • 3
1 Solution
 
appariCommented:
try changing

Updcmd.Parameters.Add("@ID", SqlDbType.Decimal).Value = id;

to

Updcmd.Parameters.Add("@ID", SqlDbType.Decimal);
Updcmd.Parameters("@ID").Value = id;

or

Updcmd.Parameters.AddWithValue("@ID", id);
0
 
kwh3856Author Commented:
Tried this one and got error
Updcmd.Parameters.Add("@ID", SqlDbType.Decimal);
Updcmd.Parameters("@ID").Value = id;-----------------------------error property used like a method

 
 
 Tried this one
 Updcmd.Parameters.AddWithValue("@ID", id);
Still get
Procedure or function 'UpdatePHICounter' expects parameter '@ID', which was not supplied.
 
 
0
 
kwh3856Author Commented:
I tried commenting this line
Updcmd.Parameters.Clear();

and I get this error message:
Invalid object name 'DRRPHICntr'.
 
 
Here is the SQL Stored Procedure:

USE [123123]
GO
/****** Object: StoredProcedure [dbo].[UpdatePHICounter] Script Date: 11/06/2008 23:27:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Proc [dbo].[UpdatePHICounter]
@ID decimal
 
AS
BEGIN
SET NOCOUNT ON
UPDATE [DRRPHICntr]
SET ID = @ID
 
SET NOCOUNT OFF
End
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
appariCommented:
did you try running the stored procedure from query analyzer?
if you are able to run it without any errors check if the user id using in your ASP.Net application has permissions on the table or not
0
 
appariCommented:
and
Updcmd.Parameters("@ID").Value = id;-----------------------------
should be
Updcmd.Parameters["@ID"].Value = id;
0
 
kwh3856Author Commented:
That did the trick.  Thank you very much.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now