Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help with my stored procedure - no records

Author  Topic 

yanivz
Starting Member

3 Posts

Posted - 2009-12-13 : 20:51:25
i have this stored procedure
ALTER PROCEDURE sp_login (
@LoginNumber VARCHAR(255),
@UserName VARCHAR(255),
@Password VARCHAR(255),
@Active BIT OUTPUT )
AS
SELECT @Active = Active
FROM Users
WHERE (LoginNumber = @LoginNumber) AND (UserName = @UserName) AND (Password = @Password)



i have records in users table and the stored procedure does not returns records when i execute.
can someone tell me what is wrong here, please ?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-12-13 : 21:01:38
does the parameters pass in matches with the column values in the tables ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-14 : 00:20:35
quote:
Originally posted by yanivz

i have this stored procedure
ALTER PROCEDURE sp_login (
@LoginNumber VARCHAR(255),
@UserName VARCHAR(255),
@Password VARCHAR(255),
@Active BIT OUTPUT )
AS
SELECT @Active = Active
FROM Users
WHERE (LoginNumber = @LoginNumber) AND (UserName = @UserName) AND (Password = @Password)



i have records in users table and the stored procedure does not returns records when i execute.
can someone tell me what is wrong here, please ?




Where you put the Return statement or select statement???


ALTER PROCEDURE sp_login (
@LoginNumber VARCHAR(255),
@UserName VARCHAR(255),
@Password VARCHAR(255),
@Active BIT OUTPUT )
AS
SELECT @Active = Active
FROM Users
WHERE (LoginNumber = @LoginNumber) AND (UserName = @UserName) AND (Password = @Password)

SELECT @Active



Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-14 : 00:34:49
Hi

You fine with this...

ALTER PROCEDURE sp_login
(
@LoginNumber VARCHAR(255),
@UserName VARCHAR(255),
@Password VARCHAR(255)
)
AS

SELECT Active
FROM Users
WHERE (LoginNumber = @LoginNumber)
AND (UserName = @UserName)
AND (Password = @Password)


-------------------------
R...
Go to Top of Page

yanivz
Starting Member

3 Posts

Posted - 2009-12-14 : 05:39:59
to khtan yes,the parameters pass in matches with the column values in the tables.

to senthil_nagore the SELECT @Active is the return value

and rajdaksha that thank you but i like to use my sp

any suggestion? still not getting records...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-12-14 : 05:48:04
can you show us how do you call sp_login ?

make sure you specify the OUTPUT keyword there

and if you are expecting a record to return from your sp, it does not. It is returning the Active via output parameter


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

yanivz
Starting Member

3 Posts

Posted - 2009-12-14 : 13:44:12
in the sql server management i just execute it and fill the parameters (not Active )

in the code i use the following :

 bool SuccessfulLogin()
{
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
// Your code should get the connection string from web.config

using (SqlConnection conn = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("sp_login"))
{
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@LoginNumber", txtLoginNumber.Text));
cmd.Parameters.Add(new SqlParameter("@UserName", txtUserName.Text));
cmd.Parameters.Add(new SqlParameter("@Password", txtPassword.Text));

SqlParameter countParameter = new SqlParameter("@Active", SqlDbType.Bit,0);
countParameter.Direction = ParameterDirection.Output;
cmd.Parameters.Add(countParameter);

conn.Open();
cmd.Connection = conn;

cmd.ExecuteNonQuery();

conn.Close();

return bool.Parse(cmd.Parameters["@Active"].Value.ToString());

}
}
}
}
Go to Top of Page

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-12-14 : 13:49:12
Do you know how to step through stored procedures (from visual studio, create a database project and then you see exactly where you missing out).
Go to Top of Page
   

- Advertisement -