Solved

Cannot figure out this problem - please help

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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 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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now