Click here to Skip to main content
16,017,167 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private Int32 check(String u, String p)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "logincheck";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = con;
        cmd.Parameters.Add("@u", SqlDbType.VarChar, 50).Value = u;
        cmd.Parameters.Add("@p", SqlDbType.VarChar, 50).Value = p;

        SqlParameter p1=new SqlParameter("@ret",SqlDbType .Int);
->//EXPLAIN NEED OF THIS PARTICULAR LINE 
     
        p1.Direction = ParameterDirection.ReturnValue;
        cmd.Parameters.Add (p1 );
        cmd.ExecuteNonQuery();
        Int32 k;
        k = Convert.ToInt32(cmd.Parameters["@ret"].Value);
        cmd.Dispose();
        return k;

     }

CAN ANY ONE EXPLAIN THIS CODE IT IS WRITTEN TO COMPARE PASSWORD PUT BY THE USER AND STORED IN DATA BASE.... :((
Can anyone explain this code. It is written to aompare password given by user abd stored in database.
Posted
Updated 28-Jun-10 4:43am
v2
Comments
Sandeep Mewara 28-Jun-10 10:44am    
1. Use pre tags for formatting code part
2. DONT use caps to write statements. It signifies shouting. It is considered rude.
shahina gupta 28-Jun-10 10:50am    
ok ....

C#
SqlParameter p1=new SqlParameter("@ret",SqlDbType .Int);->//EXPLAIN NEED OF THIS PARTICULAR LINE

It simply means that you want to create a paramter that is of Integer type.
If you check your stored procedurer, you will find that same type parameter would be expected in it.

You definded parameter name @ret of type Integer
 
Share this answer
 
Comments
shahina gupta 28-Jun-10 10:55am    
if parameter name is @ret then what is p1???
Sandeep Mewara 28-Jun-10 10:58am    
@ret is a parameter name expected in your SP.
p1 is the parameter you created in your code in ADO.NET to pass on @ret to SP.
shahina gupta 29-Jun-10 8:00am    
SP????
is it compulsory to write syntax as given above when parameter is of output or return type.
SqlParameter p1=new SqlParameter("@ret",SqlDbType .Int);


is declaring a new parameter of type int called @ret. It is a value returned form the stored procedure as denoted by ParameterDirection

In other words you are getting the value of @ret which is probably a value denoting success/failure of some description which you get into k.
 
Share this answer
 
Comments
shahina gupta 28-Jun-10 10:54am    
yes we are using @ret whose result is stored in k... then what is the need of declaring p1??
R. Giskard Reventlov 28-Jun-10 11:15am    
It's not really necessary. You could have just done cmd.Parameters.Ad(... Perhaps it was done this way for clarity of purpose to show that this parameter returns a value from the stored proc rather than supplying it.
shahina gupta 29-Jun-10 7:59am    
i had done it as cmd.parameters.add(.....) but it gives error....
is it compulsory that we have to write the syntax as given above for output parameter.
R. Giskard Reventlov 29-Jun-10 8:11am    
Does it work if you use the other syntax? It should work as stated. How have you implemented it?
shahina gupta 29-Jun-10 8:32am    
ya i have already done it....but it gives error for this

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