By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,979 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,979 IT Pros & Developers. It's quick & easy.

SP and C# problem

P: n/a
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? I know that it should be something like this:
if(sqlAdapter.SelectCommand.Parameters["@RCOUNT"].Value == 0) ,
but thereis an error:
Operator '==' cannot be applied to operands of type object type 'object'
and 'int'.
Is it possible to find out if the user with this name or e-mail exists whit
this SP and some C# code?

Could you help here?

---
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 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

In article <ua**************@TK2MSFTNGP11.phx.gbl>, vi****@yahoo.com
says...
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


You can use SqlCommand.ExecuteScalar. It returns the first column of the
first row, I.e. if it is not null, you can cast it to int and check.

Btw, why you use SqlAdapter for this? Do you need the added record back?
I don't see the point.

Sunny

Nov 16 '05 #2

P: n/a
Hi,

In article <ua**************@TK2MSFTNGP11.phx.gbl>, vi****@yahoo.com
says...
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


You can use SqlCommand.ExecuteScalar. It returns the first column of the
first row, I.e. if it is not null, you can cast it to int and check.

Btw, why you use SqlAdapter for this? Do you need the added record back?
I don't see the point.

Sunny

Nov 16 '05 #3

P: n/a
You can actually. After creating a SqlCommand, add to its Parameters
collection a param named "@RCOUNT". Set the Direction property of the param
to ParameterDirection.ReturnValue. The code should look something like this:

// create a SqlCommand
SqlCommand cmd = new SqlCommand(...);
SqlParameter param = cmd.Parameters.Add("@RCOUNT", DBType.Integer);
param.Direction = ParameterDirection.ReturnValue;

cmd.ExecuteNonQuery(); // execute the command
System.Diagnostics.Trace.WriteLine(cmd.Parameters( "@RCOUNT").Value); //
display the param value in the Output window
"Viktor Popov" <vi****@yahoo.com> wrote in message
news:ua**************@TK2MSFTNGP11.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? I know that it should be something like this:
if(sqlAdapter.SelectCommand.Parameters["@RCOUNT"].Value == 0) ,
but thereis an error:
Operator '==' cannot be applied to operands of type object type 'object'
and 'int'.
Is it possible to find out if the user with this name or e-mail exists whit this SP and some C# code?

Could you help here?

---
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 16 '05 #4

P: n/a
Hi,

Ok , I dunno about the rest of your problem , not really keen to check it
out, but I have noticed why you get the compile error.

Your line : "if(sqlAdapter.SelectCommand.Parameters["@RCOUNT"].Value == 0)"

The value property is of type object - just typecast it to an int like so :

if(Convert.ToInt32(sqlAdapter.SelectCommand.Parame ters["@RCOUNT"].Value) ==
0)

That should get it to compile

Cheers

"Viktor Popov" <vi****@yahoo.com> wrote in message
news:ua**************@TK2MSFTNGP11.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? I know that it should be something like this:
if(sqlAdapter.SelectCommand.Parameters["@RCOUNT"].Value == 0) ,
but thereis an error:
Operator '==' cannot be applied to operands of type object type 'object'
and 'int'.
Is it possible to find out if the user with this name or e-mail exists whit this SP and some C# code?

Could you help here?

---
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 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.