Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have create one store procedure spLogin.this procedure check wheather user name and password exist or not if yes return 1 if not exist return -1

but i am entering right user name and password but the store procedure returning value -1 my qurey is below
C#
SqlCommand cmd = new SqlCommand("spLogin", open());
           cmd.CommandType = CommandType.StoredProcedure;

           cmd.Parameters.Add("@LoginName", SqlDbType.VarChar).Value = clsComm.LoginName;
           cmd.Parameters.Add("@Loginpassword ", SqlDbType.VarChar).Value = clsComm.Loginpassword;

           result=cmd.ExecuteNonQuery();

Please help me out
Posted
Updated 17-Jun-12 23:28pm
v2
Comments
Savalia Manoj M 18-Jun-12 8:38am    
Please write your spLogin here.

It would be better if you check in profiler [^]what you stored procedure actually returns. I am also wondering that you use ExecuteNonQuery, where as I would expect data to be returned. ExecuteNonQuery is usually used to perform a change in data such as UPDATE, INSERT or DELETE.
 
Share this answer
 
Comments
Pradhan Gagan 18-Jun-12 5:33am    
so what would be cmd.excutescalar()?
Ankur\m/ 18-Jun-12 5:50am    
Yes if you are returning a single value.
Ankur\m/ 18-Jun-12 5:51am    
I too guess it should be because of ExecuteNonQuery(). It returns number of rows affected.
Manas Bhardwaj 18-Jun-12 6:03am    
Agree!
Ankur\m/ 18-Jun-12 12:50pm    
I think I missed clicking those stars on the right. Well it's never too late! :)
Create a stored procedure that accepts the name as input ....From that name return the password of current name...Check if both the value in text box and the result from the procedure is same or not...
C#
string Password="";
SqlDataReader ObjReader=null;
SqlCommand cmd = new SqlCommand("spLogin", open());
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@LoginName", TextBoxUserName.ToString());
ObjReader=cmd.ExecuteReader();
while(ObjReader.read())
{
   Password=ObjReader[0].toString();

}
if(Password==TextBoxPassword.toString())
{
    //User Exists;
}
else
{
    UserName are password wrong;
}
 
Share this answer
 
v2
don't use result=cmd.ExecuteNonQuery();
in place of use
result=cmd.excutescalar();
than i hope your problem will sort out.
 
Share this answer
 
v2

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