Solved

Cannot figure out this problem - please help

Posted on 2014-01-07
1
188 Views
Last Modified: 2014-01-07
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?
0
Comment
Question by:vituxa
1 Comment
 
LVL 1

Accepted Solution

by:
vituxa earned 0 total points
ID: 39762673
NEvermind!!! I was missing the following line:

cmd.CommandType = CommandType.StoredProcedure;
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question