Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i am calling this function values is not coming

Error is..
C#
userName	The name 'userName' does not exist in the current context


What I have tried:

C#
public static bool Login(string userName, string password, bool persistCookie = false)
       {

           SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mystring"].ToString();
             var para = new DynamicParameters();
               para.Add("@UserName", userName);
               var para1 = new DynamicParameters();
               para1.Add("@password", password);

               var t  = con.Query<int>("login_pro", null, null, true, 0, CommandType.StoredProcedure).ToList().SingleOrDefault();
               if (t == 1)
               {
                   return true;
               }

               else
               {
                   return false;
               }
       }





when i am calling this function
C#
bool success = objIAccountData.Login(login.username, login.password, false);
Posted
Updated 21-Jul-16 21:37pm
Comments
F-ES Sitecore 22-Jul-16 4:26am    
I don't see how that code can generate that error, are you sure that is the relevant code?
Karthik_Mahalingam 22-Jul-16 5:16am    
post the class for login
Richard Deeming 22-Jul-16 9:00am    
Why are you not passing the parameters to your stored procedure?

Assuming you're using Dapper[^], it should look something like this:

var para = new DynamicParameters();
para.Add("@UserName", userName);
para.Add("@password", password);

var t = con.Query<int>("login_pro", para, commandType: CommandType.StoredProcedure).SingleOrDefault();</int>


(There's no need to call ToList if you're then going to call SingleOrDefault immediately after.)
Richard Deeming 22-Jul-16 9:01am    

1 solution

Check your type case: C# is case sensitive, so "userName" is not the same as "username".
If your call is referencing "username":
C#
bool success = objIAccountData.Login(login.username, login.password, false);
It's possible it needs "userName"
C#
bool success = objIAccountData.Login(login.userName, login.password, false);
If you are being consistent in your naming conventions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900