473,414 Members | 1,766 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,414 software developers and data experts.

regatding stroed procedure in asp.net

Hi
i've created stored procedure in

sql server 2000 which returns a value

see the stroed procedure
CREATE PROCEDURE QA_Select_AdminOrRec
@Role varchar(50),
@username varchar(50),
@pwd varchar(50)

AS

if exists (select * from

QA_Admin_Recruiter where role = @role

and username=@username and pwd=@pwd)
return (1)
else
return (0)
GO

and in asp.net i called this stroed

procedure like this

Dim username As New OleDbParameter
username.OleDbType = OleDbType.VarChar
username.Value = txtUserName.Text

Dim pwd As New OleDbParameter
pwd.OleDbType = OleDbType.VarChar
pwd.Value = txtPassword.Text

Dim role As New OleDbParameter
role.OleDbType = OleDbType.VarChar
role.Value = Session("user")

cmd.CommandText = "QA_Select_AdminOrRec"

cmd.Parameters.Add(role)
cmd.Parameters.Add(username)
cmd.Parameters.Add(pwd)

cmd.ExecuteNonQuery().

here i've to check the value returned by stored procedure.

can anyone tell me how to write code to capture a value which returned by
the stroed procedure.

thanx in advance
yoshitha.
Nov 19 '05 #1
4 1364
Hi,

First, create a parameter "ReturnValue", set its Direction property to
ReturnValue, add it to the parameters collection (as you are using OleDb
provider, this is going to be your first parameter), then get the value from
the SP after executing ExecuteNonQuery as follows: -

Dim RetVal as Integer

Retval = CType(Cmd.Parameters("ReturnValue").Value, Integer)

HTH

Regards
Joyjit

"Yoshitha" <gu**********@rediffmail.com> wrote in message
news:uT*************@TK2MSFTNGP14.phx.gbl...
Hi
i've created stored procedure in

sql server 2000 which returns a value

see the stroed procedure
CREATE PROCEDURE QA_Select_AdminOrRec
@Role varchar(50),
@username varchar(50),
@pwd varchar(50)

AS

if exists (select * from

QA_Admin_Recruiter where role = @role

and username=@username and pwd=@pwd)
return (1)
else
return (0)
GO

and in asp.net i called this stroed

procedure like this

Dim username As New OleDbParameter
username.OleDbType = OleDbType.VarChar
username.Value = txtUserName.Text

Dim pwd As New OleDbParameter
pwd.OleDbType = OleDbType.VarChar
pwd.Value = txtPassword.Text

Dim role As New OleDbParameter
role.OleDbType = OleDbType.VarChar
role.Value = Session("user")

cmd.CommandText = "QA_Select_AdminOrRec"

cmd.Parameters.Add(role)
cmd.Parameters.Add(username)
cmd.Parameters.Add(pwd)

cmd.ExecuteNonQuery().

here i've to check the value returned by stored procedure.

can anyone tell me how to write code to capture a value which returned by
the stroed procedure.

thanx in advance
yoshitha.

Nov 19 '05 #2
hi

now i've included the statements what u have said in ur reply

see this

Dim retvalue As New OleDbParameter

retvalue.OleDbType = OleDbType.Integer

retvalue.Direction = ParameterDirection.ReturnValue

cmd.Parameters.Add(retvalue)

cmd.Parameters.Add(role)

cmd.Parameters.Add(username)

cmd.Parameters.Add(pwd)

cmd.ExecuteNonQuery()

res = CType(cmd.Parameters("retvalue").Value(), Integer)

after executing am getting error at lst line of code which is displayed
above. the error i got is below.

An OleDbParameter with ParameterName 'retvalue' is not contained by this
OleDbParameterCollection.


Nov 19 '05 #3
Hi,

In your SP, add the parameter, and instead of returning 1 or 0, write
Set Retvalue = 1
else
Set Retvalue = 0

@@Return Retvalue

HTH

Joyjit
"Yoshitha" <gu**********@rediffmail.com> wrote in message
news:On**************@TK2MSFTNGP12.phx.gbl...
hi

now i've included the statements what u have said in ur reply

see this

Dim retvalue As New OleDbParameter

retvalue.OleDbType = OleDbType.Integer

retvalue.Direction = ParameterDirection.ReturnValue

cmd.Parameters.Add(retvalue)

cmd.Parameters.Add(role)

cmd.Parameters.Add(username)

cmd.Parameters.Add(pwd)

cmd.ExecuteNonQuery()

res = CType(cmd.Parameters("retvalue").Value(), Integer)

after executing am getting error at lst line of code which is displayed
above. the error i got is below.

An OleDbParameter with ParameterName 'retvalue' is not contained by this
OleDbParameterCollection.

Nov 19 '05 #4
Yoshitha wrote:
hi

now i've included the statements what u have said in ur reply

see this

Dim retvalue As New OleDbParameter

retvalue.OleDbType = OleDbType.Integer

retvalue.Direction = ParameterDirection.ReturnValue

cmd.Parameters.Add(retvalue)

cmd.Parameters.Add(role)

cmd.Parameters.Add(username)

cmd.Parameters.Add(pwd)

cmd.ExecuteNonQuery()

res = CType(cmd.Parameters("retvalue").Value(), Integer)

after executing am getting error at lst line of code which is displayed
above. the error i got is below.

An OleDbParameter with ParameterName 'retvalue' is not contained by this
OleDbParameterCollection.


try this to get the value after the ExecuteNonQuery:
res = CType(retvalue.Value, Integer)

or set the name of the parameter before ExecuteNonQuery:
retvalue.ParameterName = "retvalue"
The problem is that you create a parameter with no name (and assign
it to the retvalue variable) and later you are trying to retrieve
that same parameter by name. There is no automatic link between
the variable named "retvalue" and some parameter with ParameterName
"retvalue"!
--
Hans Kesting
Nov 19 '05 #5

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

Similar topics

2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
1
by: Yoshitha | last post by:
Hi i've created stored procedure in sql server 2000 which returns a value see the stroed procedure CREATE PROCEDURE QA_Select_AdminOrRec @Role varchar(50),
2
by: Yoshitha | last post by:
hi all i created a stored procedure like this which retruns values am not sure whether it is correct or not. if it is wrong can you tell me where i did mistake. CREATE PROCEDURE...
1
by: bbawa1 | last post by:
I have a stored proceure whic is returning a table. Now I need ADO.Net statement So that I can pass parameters to this stored procedure and get Retuened table from stored procedure. Could you...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.