p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ADO.NET (http://p2p.wrox.com/forumdisplay.php?f=109)
-   -   how i use the Stored Procedure return value and ho (http://p2p.wrox.com/showthread.php?t=14674)

yoord June 26th, 2004 03:52 AM

how i use the Stored Procedure return value and ho
 
how i use the Stored Procedure return value and how i can use it in ADO.NET using C# Code
-----------------------------------------------

Any One Tell me how i can use N'Switch in SQL Server Stored Procedure .
When I use Such a this syntax i am encountered and stoped with a error.
the is below(Stoerd Prdocedure Code)
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~~-~-~-~-~-~
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~--~-~-~-~-~-
CREATE proc sp_check_userpass(@username nvarchar(50),@password nvarchar(50),@first nvarchar(50),@last nvarchar(50),@email nvarchar(50),@stage int )as
declare @cnt int
begin
select @cnt=count(*) from member_info where (@username=username and @password=password)
if(@cnt=0)
begin
insert into atable(first,last,username,password,stage) values(@first,@last,@username,@password,@stage)
end
else
return @cnt
end
GO
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Other thing is that when exec this store proc it must be return a value return back to the @cnt but it is return only This( The command(s) Completed succefully).
Any One guide me how i can must be do .
i must clear it that i am using this query in ASP.NET SqlClient Object To Execute Query.
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
i am using this code in my asp.net page
~-~-~-~-~-~-~-~~-~-~-~-~-~-~-~-
SqlCommand objCommand=new SqlCommand("sp_check_user_pass",objConnection);
objCommand.CommandType=CommandType.StoredProcedu re;
objCommand.Parameters.Add(new SqlParameter("@username",SqlDbType.NVarChar,50)).V alue=username.Text;
objCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarChar,50)).V alue=password.Text;
objCommand.Parameters.Add(new SqlParameter("@first",SqlDbType.NVarChar,50));//.Value=username.Text;
objCommand.Parameters["@first"].Value=first.Text;
objCommand.Parameters.Add(new SqlParameter("@last",SqlDbType.NVarChar,50));
objCommand.Parameters["@last"].Value=last.Text;
objCommand.Parameters.Add(new SqlParameter("@username",SqlDbType.NVarChar,50));
objCommand.Parameters["@username"].Value=username.Text;
objCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarChar,50));
objCommand.Parameters["@password"].Value=password.Text;
objCommand.Parameters.Add(new SqlParameter("@email",SqlDbType.NVarChar,50));
             objCommand.Parameters["@email"].Value=email.Text;
SqlParameter SqlParam=objCommand.Parameters.Add(new SqlParameter("@cnt" ,SqlDbType.Int));
             SqlParam.Direction=ParameterDirection.ReturnVa lue;
             objConnection.Open();
        try
    {
     objCommand.ExecuteNonQuery();
     rowcount=(int)objCommand.Parameters["@cnt"].Value;
    if(rowcount>0)
     {
     Response.Write("user exists"); }
    else
    {
Response.Write("user not exist");
Response.Write("cnt"+rowcount);//
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
it is run without any error but dont insert any value into table

Thanx In Advance. YoOrD.

qazi_nomi June 26th, 2004 04:36 AM

I think you are doing wrong in your sql queery which is

select @cnt=count(*) from member_info where (@username=username and @password=password)

I think it should be
@cnt = select count(*) from member_info where (username = @username and password =@password )


Love 4 all

yoord June 26th, 2004 04:10 PM

Quote:

quote:Originally posted by qazi_nomi
 I think you are doing wrong in your sql queery which is

select @cnt=count(*) from member_info where (@username=username and @password=password)

I think it should be
@cnt = select count(*) from member_info where (username = @username and password =@password )


Love 4 all
thank to u but it isnt work and stoped with many error any other solution if think i must use.
thanks in advance YoOrD.

yoord June 27th, 2004 02:04 AM

my problem yet not solved.
if any one to guide me what i must do.
regards YoOrD.


Imar June 27th, 2004 05:26 AM

Well, if it doesn't work, it's usually a very good idea to tell people what doesn't work. Just saying "and stoped with many error" is not really a very good description of the problem.

Also, realize it's weekend and many people are in an other hemisphere than you are. This means that other people are asleep while you're waiting for an answer. This means you not always get it as quick as you'd want.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Me and my monkey by Robbie Williams (Track 10 from the album: Escapology) What's This?

Hal Levy June 28th, 2004 08:39 AM

Didn't we do this before?

Here: http://p2p.wrox.com/topic.asp?TOPIC_ID=14681
And here: http://p2p.wrox.com/topic.asp?TOPIC_ID=14646
And here: http://p2p.wrox.com/topic.asp?TOPIC_ID=14084 (in the bottom of the thread)
And Here: http://p2p.wrox.com/topic.asp?TOPIC_ID=15031



Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee


All times are GMT -4. The time now is 09:34 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.