PC Review


Reply
Thread Tools Rate Thread

Error using data reader

 
 
=?Utf-8?B?U3RlcGhlbg==?=
Guest
Posts: n/a
 
      22nd Mar 2005
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;
}

 
Reply With Quote
 
 
 
 
John Bailo
Guest
Posts: n/a
 
      22nd Mar 2005
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;
> }
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem of adobe reader 8 using "Open Full Reader Search " Mike Windows XP General 1 26th Mar 2007 08:07 AM
Re: Adobe Reader Freezes on CLOSING of Reader windows roger Windows XP Help 4 12th May 2004 11:35 PM
Acrobat Reader and Adobe Reader Annie E. Windows XP General 1 27th Jan 2004 12:37 AM
Converting an Oracle Data Reader into a SQL Server Data Reader Microsoft ADO .NET 3 20th Dec 2003 06:21 PM
Sandisk 6 in 1 reader and Dazzle 8 in 1 media reader Thomas Bell Windows XP Hardware 0 27th Jul 2003 11:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:19 PM.