Avatar of vituxa
vituxa
 asked on

Cannot figure out this problem - please help

Hello. My code keeps giving me an error:
Procedure or function 'User_GetById' expects parameter '@userid', which was not supplied.
 
Here is my Stored Procedure:
USE [myDB]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

alter PROCEDURE [dbo].[User_GetById]
	@userid int
AS
BEGIN
 
   SELECT *  
	   FROM [User]
		WHERE ID = @UserId
		
END

Open in new window


And Here is my C# code where I am calling the procedure:

 public static DataTable GetUserInfo(int UserId)
    {
        SqlDataReader reader = null;
        SqlConnection con = new SqlConnection(ConnString);
        SqlCommand cmd = new SqlCommand("User_GetById", con);


        cmd.Parameters.Add("@userid", SqlDbType.Int).Value = UserId;

        con.Open();

        try
        {
            reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch(Exception err)
        {
            Utilities.Error(err);
        }

        DataTable dt = new DataTable();
        dt.Load(reader);
        return dt;
    }

Open in new window



Please tell me what I am doing wrong?
C#.NET ProgrammingMicrosoft SQL Server

Avatar of undefined
Last Comment
vituxa

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
vituxa

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck