rajeev kumar

rajeev kumar

  • 1.8k
  • 141
  • 8.1k

why ExecuteScalar allways returing 0 ?

Jun 30 2017 5:44 AM
hello sir, 
 
my sp working fine in sql but when i m calling it my c# it allways returing 0 .
please help me.
 
here is my sql sp
 
CREATE PROCEDURE test
@Email as varchar(50),
@Passwords as varchar(50)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Exists INT
IF EXISTS(SELECT UserID,Email,Passwords,f_name,l_name FROM tbl_Register WHERE Email=@Email AND Passwords=@Passwords)
BEGIN
SET @Exists = 0
END
ELSE
BEGIN
SET @Exists = 1
END
RETURN @Exists
END
 
 
and  here is my c# methods
 
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public string User_login(usrlogin ulog) // user login functions
{
int Exists= 0;
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["con"].ToString());
SqlCommand com = new SqlCommand("test", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("Email", ulog.Email);
SqlParameter p2 = new SqlParameter("Passwords", ulog.Passwords);
com.Parameters.Add(p1);
com.Parameters.Add(p2);
con.Open();
Exists = Convert.ToInt32(com.ExecuteScalar());
string IsValidate = string.Empty;
switch (Exists)
{
case 1:
IsValidate = "go";
break;
case 0:
IsValidate = "iup";
break;
}
return IsValidate;
}
 
 
 

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (1)