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();
            }
kwh3856Asked:
Who is Participating?
 
appariConnect With a Mentor Commented:
and
Updcmd.Parameters("@ID").Value = id;-----------------------------
should be
Updcmd.Parameters["@ID"].Value = id;
0
 
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
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
 
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
 
kwh3856Author Commented:
That did the trick.  Thank you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.