473,326 Members | 2,655 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,326 software developers and data experts.

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 46224
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.