473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

stored procedure result comparision

Hi ,
I have the following SP:
CREATE PROCEDURE prSVUSERINFO
@USRNAM VARCHAR(20),
@USRPSW VARCHAR(20),
@NAME VARCHAR(64),
@ADDR VARCHAR(74),
@EML VARCHAR(64),
@ROLE VARCHAR(6),
@RCOUNT INT OUTPUT
AS
IF NOT EXISTS( SELECT * FROM BLEK.USERS A WHERE A.USERNAME=@USRNAM OR
A.USEREMAIL=@EML)
BEGIN
INSERT INTO
ESTATE.BLEK.USERS(Username,UserPass,RealName,UserA ddr,UserEmail,UserRole)
VALUES(@USRNAM,@USRPSW,@NAME,@ADDR,@EML,@ROLE)
END
ELSE
RETURN SELECT @RCOUNT=@@ROWCOUNT

Could I use somehow @RCOUNT in ASP.NET/C# to find out if the username
is already in use or not?

Thank you!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.
Nov 18 '05 #1
10 1346
yes, you should be able to get the paramaters("@Ident").value
that's not exact syntax but should get you close.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Viktor Popov" <vi****@yahoo.com> wrote in message
news:eH*************@TK2MSFTNGP10.phx.gbl...
Hi ,
I have the following SP:
CREATE PROCEDURE prSVUSERINFO
@USRNAM VARCHAR(20),
@USRPSW VARCHAR(20),
@NAME VARCHAR(64),
@ADDR VARCHAR(74),
@EML VARCHAR(64),
@ROLE VARCHAR(6),
@RCOUNT INT OUTPUT
AS
IF NOT EXISTS( SELECT * FROM BLEK.USERS A WHERE A.USERNAME=@USRNAM OR
A.USEREMAIL=@EML)
BEGIN
INSERT INTO
ESTATE.BLEK.USERS(Username,UserPass,RealName,UserA ddr,UserEmail,UserRole)
VALUES(@USRNAM,@USRPSW,@NAME,@ADDR,@EML,@ROLE)
END
ELSE
RETURN SELECT @RCOUNT=@@ROWCOUNT

Could I use somehow @RCOUNT in ASP.NET/C# to find out if the username is already in use or not?

Thank you!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.

Nov 18 '05 #2
Thanks for the reply!

This is my if statement

if(sqlAdapter.SelectCommand.Parameters["@RCOUNT"].Value == 0) , but there
is an error:

Operator '==' cannot be applied to operands of type object type 'object'
and 'int'.

I know that I'm close but.....

Could you help here?

Thanks!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.

Nov 18 '05 #3
In SqlCommand (or similar class for other databases) setup a parameter with
property Direction set to ReturnValue.

Eliyahu

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:eH*************@TK2MSFTNGP10.phx.gbl...
Hi ,
I have the following SP:
CREATE PROCEDURE prSVUSERINFO
@USRNAM VARCHAR(20),
@USRPSW VARCHAR(20),
@NAME VARCHAR(64),
@ADDR VARCHAR(74),
@EML VARCHAR(64),
@ROLE VARCHAR(6),
@RCOUNT INT OUTPUT
AS
IF NOT EXISTS( SELECT * FROM BLEK.USERS A WHERE A.USERNAME=@USRNAM OR
A.USEREMAIL=@EML)
BEGIN
INSERT INTO
ESTATE.BLEK.USERS(Username,UserPass,RealName,UserA ddr,UserEmail,UserRole)
VALUES(@USRNAM,@USRPSW,@NAME,@ADDR,@EML,@ROLE)
END
ELSE
RETURN SELECT @RCOUNT=@@ROWCOUNT

Could I use somehow @RCOUNT in ASP.NET/C# to find out if the username is already in use or not?

Thank you!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.

Nov 18 '05 #4
It doesn't work with SqlAdapter and SqlCommand.
Could you explain how exactly should I do that?
Thanks
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.
Nov 18 '05 #5
Convert.ToInt32(adapterStuff) == 0

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Viktor Popov" <vi****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Thanks for the reply!

This is my if statement

if(sqlAdapter.SelectCommand.Parameters["@RCOUNT"].Value == 0) , but there
is an error:

Operator '==' cannot be applied to operands of type object type 'object'
and 'int'.

I know that I'm close but.....

Could you help here?

Thanks!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.

Nov 18 '05 #6
Are you replying to my message? If you are, look at the MSDN help topic
"Using Stored Procedures with a Command" . It includes an example of using
ReturnValue.

Eliyahu

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:et**************@TK2MSFTNGP09.phx.gbl...
It doesn't work with SqlAdapter and SqlCommand.
Could you explain how exactly should I do that?
Thanks
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.

Nov 18 '05 #7
I've read it but these SPs return rowsets. My SP return a INT. Is it the
same way of implementing?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.
Nov 18 '05 #8
Another resource:
http://support.microsoft.com/default...b;EN-US;310070

ReturnValue type is designed exactly for returning values, not rowset. The
only thing that is not clear for me is how to get return value with
SqlDataAdapter. Using SqlDataReader is straightforward: setup parameter,
execute the reader, close the reader and get the parameter's value.

Eliyahu

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:e9**************@tk2msftngp13.phx.gbl...
I've read it but these SPs return rowsets. My SP return a INT. Is it the
same way of implementing?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.

Nov 18 '05 #9
yes, look at sqlcommand. besure to decalre the parameter as an out. also the
values will not be set until after all result sets. a common approach is to
close the connection

air code:

SqlCommand cmd = new SqlCommand("prSVUSERINFO",new
SqlConnection(connectString));
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@USRNAM,SqlDbType.VarChar,20). Value = username;
....

cmd.Parameters.Add("@RCOUNT ,SqlDbType.Int,4).Direction =
ParameterDirection.Output;
cmd.ExecuteNonQuery();
int rCount = cmd.Parameters["@RCOUNT"].Value as int;
of course the way your sp is written rCount will allways be 0

-- bruce (sqlwork.com)
"Viktor Popov" <vi****@yahoo.com> wrote in message
news:eH*************@TK2MSFTNGP10.phx.gbl...
Hi ,
I have the following SP:
CREATE PROCEDURE prSVUSERINFO
@USRNAM VARCHAR(20),
@USRPSW VARCHAR(20),
@NAME VARCHAR(64),
@ADDR VARCHAR(74),
@EML VARCHAR(64),
@ROLE VARCHAR(6),
@RCOUNT INT OUTPUT
AS
IF NOT EXISTS( SELECT * FROM BLEK.USERS A WHERE A.USERNAME=@USRNAM OR
A.USEREMAIL=@EML)
BEGIN
INSERT INTO
ESTATE.BLEK.USERS(Username,UserPass,RealName,UserA ddr,UserEmail,UserRole)
VALUES(@USRNAM,@USRPSW,@NAME,@ADDR,@EML,@ROLE)
END
ELSE
RETURN SELECT @RCOUNT=@@ROWCOUNT

Could I use somehow @RCOUNT in ASP.NET/C# to find out if the username is already in use or not?

Thank you!
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.

Nov 18 '05 #10
Thanks for the answer, Bruce!
I have changed the SP, I didn't know that the value of @RCOUNT is everytime
0.I thought that " if EXISTS( select * from ....)" changes the value of
@@ROWCOUNT...
I rewrite it this way:
CREATE PROCEDURE prSVUSERINFO
@USRNAM VARCHAR(20),
@USRPSW VARCHAR(20),
@NAME VARCHAR(64),
@ADDR VARCHAR(74),
@EML VARCHAR(64),
@ROLE VARCHAR(6),
@FLAG INT OUTPUT

AS

IF NOT EXISTS( SELECT * FROM BLEK.USERS A WHERE A.USERNAME=@USRNAM OR
A.USEREMAIL=@EML)
BEGIN
INSERT INTO
ESTATE.BLEK.USERS(Username,UserPass,RealName,UserA ddr,UserEmail,UserRole)
VALUES(@USRNAM,@USRPSW,@NAME,@ADDR,@EML,@ROLE)
SET @FLAG=0
RETURN @FLAG
END
ELSE
BEGIN
SET @FLAG=1
RETURN @FLAG
END

and I check if rCount ==0{ some code}
else{
some code}
Now everything works. Could you check the SP and if I could optimize it
somehow, please tell me:)
Do you know how I could do that check using @@ROWCOUNT?
Thank you very much!

Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.721 / Virus Database: 477 - Release Date: 16.7.2004 a.
Nov 18 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Darko Jovisic | last post by:
Hi! How can I save a result set from a stored procedure into a table? Can you show me some examples? Thank you! Darko
4
by: marc | last post by:
I've been developing a stored procedure that uses a user defined function in the query portion of the procedure. However, since the end product needs to allow for dynamic table names, the UDF will...
3
by: nandan | last post by:
Hi, Has any one ever compared the performance of calling a DataTable's Select method with a stored procedure doing the same thing? My point is: dataRows = DataTable.Select(filter) is better or...
4
by: Jaraba | last post by:
In Microsoft SQL I can run the following command: insert into table execute proc1 to insert data into a table. Is there a comparable way to do this in DB2?
2
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different...
2
by: Krij | last post by:
Hi, I'm a student and I have the following working example that troubles me (in SQL Server 2005): CREATE PROCEDURE dbo.CustomersOrderHistory ( @Firstname varchar(7) OUTPUT) AS SELECT ...
2
by: Frank Swarbrick | last post by:
I've been trying the following in DB2/LUW since version 8.2 (9.1 and now 9.5) and I've never been able to get this to work. (Not this exact SP, which didn't exist prior to version 9, but just any...
2
by: Mark B | last post by:
What amendments to the ASP.NET 3.5. VB code below output the MSSQL stored procedure dataset result to XML (as a response stream)? (I also guessing to use Response.ContentType = "text/xml"): ...
4
by: jack1257 | last post by:
Hi How to import the stored procedure result to the excel sheet.please provide stored procedure code
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.