Solved

Cannot figure out this problem - please help

Posted on 2014-01-07
1
189 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

726 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