473,411 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Error using data reader

I'm having terrible trouble working out where I have gone wrong in my code
below. In the data layer I have two methods and i'm basically returning a
command and using it and then returning a reader. Unfortunately i'm getting
the following error on the line:
reader = cmdLogin.ExecuteReader();
Error Message: -
Procedure 'LoginValidation' expects parameter '@p_UserName', which was not
supplied.

Not sure where I have went wrong as I reckon I have supplied it. Can someone
have a look at this and give me some suggestions please.
Thanks for any help you can give.

public static SqlDataReader LoginValidateUser(string p_sUserName,
SqlConnection p_conn)
{
SqlCommand cmdLogin = null;
SqlDataReader reader = null;

try
{
cmdLogin = LoginValidateUserCommand(p_sUserName);
//Set the connection instance
cmdLogin.Connection = p_conn;
if (!(ConnectionState.Open == p_conn.State))
{
p_conn.Open();
}
// execute the reader

reader = cmdLogin.ExecuteReader();
}
catch (Exception ex)
{
throw ex;
}
finally
{

cmdLogin.Dispose();
}
return reader;
}

private static SqlCommand LoginValidateUserCommand(string p_sUserName)
{
SqlCommand cmdLogin = null;
try
{
cmdLogin = new SqlCommand();
cmdLogin.CommandText = "LoginValidation";
cmdLogin.CommandType = CommandType.StoredProcedure;

//Create Parameter
SqlParameter @p_UserName = new SqlParameter
("username", System.Data.SqlDbType.Char);
@p_UserName.Direction = ParameterDirection.Input;
// set parameter value
@p_UserName.Value = p_sUserName;

}
catch (Exception e)
{
throw(e);
}
return cmdLogin;
}

Nov 17 '05 #1
1 2101
You create the parameter, but you never add it to the parameters
collection of the command.
Stephen wrote:
I'm having terrible trouble working out where I have gone wrong in my code
below. In the data layer I have two methods and i'm basically returning a
command and using it and then returning a reader. Unfortunately i'm getting
the following error on the line:
reader = cmdLogin.ExecuteReader();
Error Message: -
Procedure 'LoginValidation' expects parameter '@p_UserName', which was not
supplied.

Not sure where I have went wrong as I reckon I have supplied it. Can someone
have a look at this and give me some suggestions please.
Thanks for any help you can give.

public static SqlDataReader LoginValidateUser(string p_sUserName,
SqlConnection p_conn)
{
SqlCommand cmdLogin = null;
SqlDataReader reader = null;

try
{
cmdLogin = LoginValidateUserCommand(p_sUserName);
//Set the connection instance
cmdLogin.Connection = p_conn;
if (!(ConnectionState.Open == p_conn.State))
{
p_conn.Open();
}
// execute the reader

reader = cmdLogin.ExecuteReader();
}
catch (Exception ex)
{
throw ex;
}
finally
{

cmdLogin.Dispose();
}
return reader;
}

private static SqlCommand LoginValidateUserCommand(string p_sUserName)
{
SqlCommand cmdLogin = null;
try
{
cmdLogin = new SqlCommand();
cmdLogin.CommandText = "LoginValidation";
cmdLogin.CommandType = CommandType.StoredProcedure;

//Create Parameter
SqlParameter @p_UserName = new SqlParameter
("username", System.Data.SqlDbType.Char);
@p_UserName.Direction = ParameterDirection.Input;
// set parameter value
@p_UserName.Value = p_sUserName;

}
catch (Exception e)
{
throw(e);
}
return cmdLogin;
}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stephen | last post by:
I'm having terrible trouble working out where I have gone wrong in my code below. In the data layer I have two methods and i'm basically returning a command and using it and then returning a...
2
by: jack | last post by:
hi all im facing a problem in error handelling. what im doing is getting the images from the database to my csharp application form .. now here in some of the records contains images along with...
0
by: Tim::.. | last post by:
Hi, Can someone please tell me why I get this error when I try to build my ASP.NET application??? Could not load type 'CPNNet.Global'. Line 1: <%@ Application Codebehind="Global.asax.vb"...
0
by: Meer | last post by:
Hi, I'm having problem to read *.DBF (DBase File) using ASP.NET. Below is my code, taken from one of forumer here.... Dim connection As OleDbConnection Dim command As OleDbCommand Dim reader As...
0
by: Brent | last post by:
After six months flawless operation, I'm suddenly getting this error: "Unable to read data from the transport connection." The code* hasn't changed, and from what I can see, neither have the IP...
3
by: Doug Durrett | last post by:
I'm having an issue and wanted to pass it by everyone to see what you think. Here is my code. //Code Start searchs = new...
13
by: lithoman | last post by:
I'm stumped here. I run the procedure Batch_Select against the database with @ID=18 and I get the expected data. When it loads into a SqlDataReader, it gets messed up somehow. Initially, after the...
0
by: mark4asp | last post by:
I'm accessing the website locally via IIS. I get an error message shown in DropDownList2: I can't see what I'm doing wrong. I changed CascadingDropDown1.Category from "Continent" to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.