473,474 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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;
}

Jul 21 '05 #1
1 1426
You never add that parameter to the parameter collection of the command
object.

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:E5**********************************@microsof t.com...
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;
}

Jul 21 '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...
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...
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...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.