473,804 Members | 3,557 Online
Bytes | Software Development & Data Engineering Community
+ 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.Connection String = "workstatio n id=SBGBHO;packe t size=4096;user id=sa;data source=SBGBHO;p ersist security info=True;initi al catalog=hsData; password=hardik "

Dim mycmd As New SqlCommand

mycmd.Connectio n = CONN

mycmd.CommandTe xt = "strproc"

mycmd.CommandTy pe = CommandType.Sto redProcedure

Dim Param1 As New SqlClient.SqlPa rameter("@dbase name", SqlDbType.Char, DbName)

Dim Param2 As New SqlClient.SqlPa rameter("@tblna me", SqlDbType.Char, tblName)

Dim Param3 As New SqlClient.SqlPa rameter("@dbase _id", dbid)

Dim Param4 As New SqlClient.SqlPa rameter("@table _id", tbid)

Param1.Directio n = ParameterDirect ion.Input

Param2.Directio n = ParameterDirect ion.Input

Param3.Directio n = ParameterDirect ion.Output

Param4.Directio n = ParameterDirect ion.Output

mycmd.Parameter s.Add(Param1)

mycmd.Parameter s.Add(Param2)

mycmd.Parameter s.Add(Param3)

mycmd.Parameter s.Add(Param4)

CONN.Open()

mycmd.ExecuteNo nQuery()

CONN.Close()

CONN = Nothing

Nov 21 '05 #1
2 46262
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********@hot mail.com> wrote in message
news:e%******** ********@TK2MSF TNGP09.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.Connection String = "workstatio n id=SBGBHO;packe t size=4096;user
id=sa;data source=SBGBHO;p ersist security info=True;initi al
catalog=hsData; password=hardik "
Dim mycmd As New SqlCommand
mycmd.Connectio n = CONN
mycmd.CommandTe xt = "strproc"
mycmd.CommandTy pe = CommandType.Sto redProcedure
Dim Param1 As New SqlClient.SqlPa rameter("@dbase name", SqlDbType.Char,
DbName)
Dim Param2 As New SqlClient.SqlPa rameter("@tblna me", SqlDbType.Char,
tblName)
Dim Param3 As New SqlClient.SqlPa rameter("@dbase _id", dbid)
Dim Param4 As New SqlClient.SqlPa rameter("@table _id", tbid)
Param1.Directio n = ParameterDirect ion.Input
Param2.Directio n = ParameterDirect ion.Input
Param3.Directio n = ParameterDirect ion.Output
Param4.Directio n = ParameterDirect ion.Output
mycmd.Parameter s.Add(Param1)
mycmd.Parameter s.Add(Param2)
mycmd.Parameter s.Add(Param3)
mycmd.Parameter s.Add(Param4)
CONN.Open()
mycmd.ExecuteNo nQuery()
CONN.Close()
CONN = Nothing
Nov 21 '05 #2
dbid=param3.val ue
tbid=param4.val ue

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

With cmd

..Connection = con

..CommandTimeou t = 120

..CommandType = CommandType.Sto redProcedure

..CommandText = "br_updateboxwe ights"

..Parameters.Ad d("@loadno", SqlDbType.Int)

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

End With
--
--Eric Cathell, MCSA
"Hardik Shah" <ha********@hot mail.com> wrote in message news:e%******** ********@TK2MSF TNGP09.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.Connection String = "workstatio n id=SBGBHO;packe t size=4096;user id=sa;data source=SBGBHO;p ersist security info=True;initi al catalog=hsData; password=hardik "

Dim mycmd As New SqlCommand

mycmd.Connectio n = CONN

mycmd.CommandTe xt = "strproc"

mycmd.CommandTy pe = CommandType.Sto redProcedure

Dim Param1 As New SqlClient.SqlPa rameter("@dbase name", SqlDbType.Char, DbName)

Dim Param2 As New SqlClient.SqlPa rameter("@tblna me", SqlDbType.Char, tblName)

Dim Param3 As New SqlClient.SqlPa rameter("@dbase _id", dbid)

Dim Param4 As New SqlClient.SqlPa rameter("@table _id", tbid)

Param1.Directio n = ParameterDirect ion.Input

Param2.Directio n = ParameterDirect ion.Input

Param3.Directio n = ParameterDirect ion.Output

Param4.Directio n = ParameterDirect ion.Output

mycmd.Parameter s.Add(Param1)

mycmd.Parameter s.Add(Param2)

mycmd.Parameter s.Add(Param3)

mycmd.Parameter s.Add(Param4)

CONN.Open()

mycmd.ExecuteNo nQuery()

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
6707
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 Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
1
1490
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 procedure, i can access the variable this way:
4
13472
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 not work. I've been trying to get this to work with converting the UDF to a procedure, but I'm having no luck. Here is the background on what I'm trying to accomplish. I need to perform a sub-identity on a table, I have the normal identity set,...
8
14010
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 stack. this contains the arguments this function was called with, address to return to after return from this function (the location in the previous stack frame), location of previous frame on stack (base or start of this frame) and local variables...
2
5464
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
5
6859
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 info sent to the stored procedure makes the stored procedure fail. I want to be able to display a label indicating they should try again, if this is the case. I can't use row count, because the stored procedure doesn't get that far. What...
7
9719
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 for this being to stop the user thinking the application has frozen when in fact it is just waiting for a long SP to complete. Another reason for doing it like this is that I also have had a problem in the past where the SP takes longer than the...
1
3257
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 As New SqlClient.SqlConnection(strRegistry)
9
4148
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. When calling the stored procedure from VB.NET, in the CommandText, can I just say "INSERT_INTO_MYTABLE '12345'" instead of calling it with "INSERT_INTO_MYTABLE" then do the following : OleDbCommand2.Parameters.Add("@Account", SqlDbType.VarChar, 10)...
9
2471
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 through the application in Visual Studio .NET 2003 the application an exception when it executes the query.
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10337
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9160
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4301
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 we have to send another system
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.