473,465 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get Return value from SQL Stored Procedure.

Hi,

I have created a sql stored procedure which returns two values. it runs successfully from query analyser. I want to run it from my vb.net code , it runs without any error but it don't store the value of return parameter (i.e. dbid,tbid) . Here I paste my code. Please tell me where I am wrong.

Thanks in advance.

Hardik shah.

==========

Dim dbid As Integer

Dim tbid As Integer

Dim myReader As SqlDataReader

Dim CONN As New SqlConnection

CONN.ConnectionString = "workstation id=SBGBHO;packet size=4096;user id=sa;data source=SBGBHO;persist security info=True;initial catalog=hsData;password=hardik"

Dim mycmd As New SqlCommand

mycmd.Connection = CONN

mycmd.CommandText = "strproc"

mycmd.CommandType = CommandType.StoredProcedure

Dim Param1 As New SqlClient.SqlParameter("@dbasename", SqlDbType.Char, DbName)

Dim Param2 As New SqlClient.SqlParameter("@tblname", SqlDbType.Char, tblName)

Dim Param3 As New SqlClient.SqlParameter("@dbase_id", dbid)

Dim Param4 As New SqlClient.SqlParameter("@table_id", tbid)

Param1.Direction = ParameterDirection.Input

Param2.Direction = ParameterDirection.Input

Param3.Direction = ParameterDirection.Output

Param4.Direction = ParameterDirection.Output

mycmd.Parameters.Add(Param1)

mycmd.Parameters.Add(Param2)

mycmd.Parameters.Add(Param3)

mycmd.Parameters.Add(Param4)

CONN.Open()

mycmd.ExecuteNonQuery()

CONN.Close()

CONN = Nothing

Nov 21 '05 #1
2 46238
Hi,

Here is a link on how to get a return value. You really should not
post your passwords in the newsgroup.

http://msdn.microsoft.com/library/de...turnvalues.asp

Ken
--------------------------

"Hardik Shah" <ha********@hotmail.com> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
Hi,
I have created a sql stored procedure which returns two values. it runs
successfully from query analyser. I want to run it from my vb.net code , it
runs without any error but it don't store the value of return parameter
(i.e. dbid,tbid) . Here I paste my code. Please tell me where I am wrong.
Thanks in advance.
Hardik shah.
==========
Dim dbid As Integer
Dim tbid As Integer
Dim myReader As SqlDataReader
Dim CONN As New SqlConnection
CONN.ConnectionString = "workstation id=SBGBHO;packet size=4096;user
id=sa;data source=SBGBHO;persist security info=True;initial
catalog=hsData;password=hardik"
Dim mycmd As New SqlCommand
mycmd.Connection = CONN
mycmd.CommandText = "strproc"
mycmd.CommandType = CommandType.StoredProcedure
Dim Param1 As New SqlClient.SqlParameter("@dbasename", SqlDbType.Char,
DbName)
Dim Param2 As New SqlClient.SqlParameter("@tblname", SqlDbType.Char,
tblName)
Dim Param3 As New SqlClient.SqlParameter("@dbase_id", dbid)
Dim Param4 As New SqlClient.SqlParameter("@table_id", tbid)
Param1.Direction = ParameterDirection.Input
Param2.Direction = ParameterDirection.Input
Param3.Direction = ParameterDirection.Output
Param4.Direction = ParameterDirection.Output
mycmd.Parameters.Add(Param1)
mycmd.Parameters.Add(Param2)
mycmd.Parameters.Add(Param3)
mycmd.Parameters.Add(Param4)
CONN.Open()
mycmd.ExecuteNonQuery()
CONN.Close()
CONN = Nothing
Nov 21 '05 #2
dbid=param3.value
tbid=param4.value

also you can really lighten your coding load either by using the DAAB 2.0 or

With cmd

..Connection = con

..CommandTimeout = 120

..CommandType = CommandType.StoredProcedure

..CommandText = "br_updateboxweights"

..Parameters.Add("@loadno", SqlDbType.Int)

..Parameters("@loadno").Value = loadnumber

End With
--
--Eric Cathell, MCSA
"Hardik Shah" <ha********@hotmail.com> wrote in message news:e%****************@TK2MSFTNGP09.phx.gbl...
Hi,

I have created a sql stored procedure which returns two values. it runs successfully from query analyser. I want to run it from my vb.net code , it runs without any error but it don't store the value of return parameter (i.e. dbid,tbid) . Here I paste my code. Please tell me where I am wrong.

Thanks in advance.

Hardik shah.

==========

Dim dbid As Integer

Dim tbid As Integer

Dim myReader As SqlDataReader

Dim CONN As New SqlConnection

CONN.ConnectionString = "workstation id=SBGBHO;packet size=4096;user id=sa;data source=SBGBHO;persist security info=True;initial catalog=hsData;password=hardik"

Dim mycmd As New SqlCommand

mycmd.Connection = CONN

mycmd.CommandText = "strproc"

mycmd.CommandType = CommandType.StoredProcedure

Dim Param1 As New SqlClient.SqlParameter("@dbasename", SqlDbType.Char, DbName)

Dim Param2 As New SqlClient.SqlParameter("@tblname", SqlDbType.Char, tblName)

Dim Param3 As New SqlClient.SqlParameter("@dbase_id", dbid)

Dim Param4 As New SqlClient.SqlParameter("@table_id", tbid)

Param1.Direction = ParameterDirection.Input

Param2.Direction = ParameterDirection.Input

Param3.Direction = ParameterDirection.Output

Param4.Direction = ParameterDirection.Output

mycmd.Parameters.Add(Param1)

mycmd.Parameters.Add(Param2)

mycmd.Parameters.Add(Param3)

mycmd.Parameters.Add(Param4)

CONN.Open()

mycmd.ExecuteNonQuery()

CONN.Close()

CONN = Nothing

Nov 21 '05 #3

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

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
1
by: - | last post by:
this is one way of creating a stored procedure in mysql: CREATE PROCEDURE some_procedure (IN value1, OUT value2) BEGIN SELECT ... INTO value2 FROM .... END// and if called from another...
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...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
5
by: Sandy | last post by:
Hello - I need a good example of how to take a return value from a stored procedure and use it in vb code. I have an app that searches a database by city and state. If a user makes a typo, the...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
1
by: csgraham74 | last post by:
Hi Guys, Im attempting to get an output value from my stored procedure. Im pulling my hair out at this one. any help appreciated. my code is as follows: Dim cnstring As String Dim iConn...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
9
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug...
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...
1
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.