Click here to Skip to main content
15,885,952 members
Please Sign up or sign in to vote.
1.00/5 (6 votes)
See more:
public int Validate_login(string Username, string Password)
    {
        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["connect"]);
        SqlCommand cmdselect = new SqlCommand();
        cmdselect.CommandType = CommandType.StoredProcedure;
        cmdselect.CommandText = "Login_detail1";
        cmdselect.Parameters.Add("@Username", Username);
        cmdselect.Parameters.Add("@Password", Password);
        cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4);
        cmdselect.Parameters["@OutRes"].Direction = ParameterDirection.Output;
        cmdselect.Connection = con;
        int Results = 0;
        try
        {
            con.Open();
            cmdselect.ExecuteNonQuery();
            Results = (int)cmdselect.Parameters["@OutRes"].Value;
        }
        catch (SqlException ex)
        {
            lblresult.Text = ex.Message;
        }
        finally
        {
            cmdselect.Dispose();
            if (con != null)
            {
                con.Close();
            }
        }
        return Results;
    }
Posted
Comments
LittleYellowBird 26-Aug-11 7:20am    
Is this homework? If so ask about the bits you don't understand. If not what is the problem, what isn't working?
Herman<T>.Instance 26-Aug-11 7:20am    
why? what is your problem?
stanly jeba singh 26-Aug-11 8:42am    
I do not understood the following lines in my code i am a beginner in dotnet

cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4);
cmdselect.Parameters["@OutRes"].Direction = ParameterDirection.Output;
cmdselect.Connection = con;
int Results = 0;
try
{
con.Open();
cmdselect.ExecuteNonQuery();
Results = (int)cmdselect.Parameters["@OutRes"].Value;
}
catch (SqlException ex)
{
lblresult.Text = ex.Message;
}
finally
{
cmdselect.Dispose();
if (con != null)
{
con.Close();
}
}
return Results;
}
Dylan Morley 26-Aug-11 7:29am    
You explain it to me. Then I'll tell you if you're right or wrong.

I may rate your answers in the form of a grade, such as 'A - outstanding' or 'E - Must try harder, see me'

......,

SqlCommand[^]
SqlConnection
[^]
ExecuteNonQuery [^]

might help you :)
 
Share this answer
 
It retrieves a value that indicates whether or not the userid/password is valid. If you need an explanation of such simple code, you're either a manager or a student. Either way, you have no business looking at production code. Furthermore, the fact that there are no comments indicates that whoever wrote the code needs a lesson in maintainability.

EDIT =====================

The line you don't understand is called an ouput parameter that SQL sends back as a result of the query. Think of it as a method return value like you get in C#.
 
Share this answer
 
v2
Comments
Wayne Gaylard 26-Aug-11 7:42am    
Hey, managers can codez!

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