Solved

Cannot figure out this problem - please help

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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…

777 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