Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 19th, 2004, 02:40 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default Problem In Parameterized ADO.NET Stored Procedure

I have Problem in using Stored Procedure in ADO.Net With C# .
i am usin Such a code The send Username And Password to a sql server db and return the nubmer that specifying if a record is found or not found but i dont get proper result in any one to help me.
 stored procedure code
CREATE proc sp_check_user_pass(@username nvarchar(50),@password nvarchar(50) )as
begin
select count(*) as num from member_info where (@username=username and @password=password)
return @@rowcount
end
GO

and in the my asp.net page i am using such a below code
Code:
SqlConnection objConnection=new SqlConnection(strConnection);  
  if(Page.IsPostBack)
    {
      SqlCommand objCommand=new        SqlCommand"sp_check_user_pass",objConnection);
SqlConnection(strConnection);
    objCommand.CommandType=CommandType.StoredProcedure;
    objCommand.Parameters.Add(new SqlParameter("@username",SqlDbType.NVarChar,50)).Value=username.Text;
objCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarChar,50)).Value=password.Text;
 SqlParameter SqlParam=objCommand.Parameters.Add(new SqlParameter("@RowCount" ,SqlDbType.Int));
             SqlParam.Direction=ParameterDirection.ReturnValue;
             objConnection.Open();
              try
               {
                    objCommand.ExecuteNonQuery();
                 int rowcount=(int);                 objCommand.Parameters["@RowCount"].Value;
con_open.Text="Number Of Affected Records= "+rowcount;
It must return 1 when no such record is exist in database otherwise return 0 .
but its return 1 for both of them.
Any One Help
And Any One to tell me how I can declare variable in Stored Procedure that i get or return record count(*)
thankx in advance.
YoOrD.


__________________
       YoOrD .
Beauty is not on the face
Beauty is on the heart
~~<<Ghibran Khalil>>~~
 
Old June 19th, 2004, 03:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear friend of course it will always return 1 bc u used @@rowcount
@@rowcount return the number of effected rows & u have already COUNT on ur select, so it counts & of course is always 1. bc it has 1 row effected.
my suggestion is alter ur SP to:
Code:
DECLARE @Cnt int
select @Cnt=count(*) as num 
from member_info 
where (@username=username and @password=password)
return @Cnt
It'll OK! HTH.

Always:),
Hovik Melkomian.
 
Old June 19th, 2004, 04:31 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by melvik
 Dear friend of course it will always return 1 bc u used @@rowcount
@@rowcount return the number of effected rows & u have already COUNT on ur select, so it counts & of course is always 1. bc it has 1 row effected.
my suggestion is alter ur SP to:
Code:
DECLARE @Cnt int
select @Cnt=count(*) as num 
from member_info 
where (@username=username and @password=password)
return @Cnt
It'll OK! HTH.

Always:),
Hovik Melkomian.
Thank U veryfor your reply Much I Understand how i get missed

 
Old June 19th, 2004, 05:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

u r always welcome!

Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
.net with oracle stored procedure vgsgowrisankar C# 2005 1 April 16th, 2008 03:14 PM
ado and oracle procedure problem plz help zrtv Pro VB Databases 9 February 28th, 2008 01:00 PM
ADO Create Procedure problem xiangchendub Access VBA 3 January 23rd, 2008 09:37 AM
Stored Procedure Problem kwilliams SQL Server 2000 7 June 23rd, 2006 03:03 PM
Parameterized CRystal report & Stored procedure jay4ever_2000 ASP.NET 1.0 and 1.1 Professional 3 June 6th, 2006 08:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.