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

How to get return value of sqlstored procedure in vb.net

Hi,

This is my code. Here I want to retrieve return value of stored procedure. when I am executing this, I am receiving exception as string[1] string invalid index[0].


coding..




cmd.CommandText = "sp_dat_enc"
Dim params() As OleDbParameter = {New OleDbParameter("@pVisitDates", r("visit_dates").ToString)}
Dim ret_val As New OleDbParameter("@DataOut", OleDbType.VarChar)
ret_val.Direction = ParameterDirection.ReturnValue
cmd.Parameters.Clear()
cmd.Parameters.AddRange(params)
cmd.Parameters.Add(ret_val)
Dim ddr As OleDbDataReader = cmd.ExecuteReader
Jun 14 '10 #1
1 1898
sanndeb
33
Expand|Select|Wrap|Line Numbers
  1. Dim connectionString As String = "Server=L40\YUKON; Initial Catalog=AdventureWorks; Integrated Security=True;"
  2. Using conn As New SqlConnection(connectionString)
  3.     Using cmd As New SqlCommand("dbo.GetCountByLastName")
  4.         cmd.CommandType = CommandType.StoredProcedure
  5.         cmd.Parameters.Add(New SqlParameter("@LastName", "Alexander"))
  6.  
  7.         Dim countParameter As New SqlParameter("@LastNameCount", 0)
  8.         countParameter.Direction = ParameterDirection.Output
  9.         cmd.Parameters.Add(countParameter)
  10.  
  11.         conn.Open()
  12.         cmd.Connection = conn
  13.  
  14.         cmd.ExecuteNonQuery()
  15.         Dim count As Integer = Int32.Parse(cmd.Parameters("@LastNameCount").Value.ToString())
  16.         Response.Write("<p>Count: " & count.ToString())
  17.         conn.Close()
  18.     End Using
  19. End Using

Found On Net, May Be Helpful To You...
Jun 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: JT | last post by:
how can i see a stored procedures return value in ASP??
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...
1
by: Greg Smith | last post by:
I am trying to write a SQL query that will return a record count to my C# application. I wrote the following query: ALTER PROCEDURE up_justification_duplicate AS SELECT COUNT(*) FROM...
1
by: Neo Chou | last post by:
Greetings! I met the same question as in ADO a few months ago. I'm working on MS SQL Server 2000. I have a stored procedure that returns a return value as well as a record set (by "select"...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
3
by: Geraldine Hobley | last post by:
Hello, I have a stored procedure that returns a value but does not select any rows as shown below How can I access the value of this return value from the database using datasets or dataadapters. ...
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...
2
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different...
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...
12
by: Dooza | last post by:
I have a stored procedure that takes a number of inputs, does a bulk insert, and then outputs a recordset. When I run the stored procedure in Server Management Studio I also get a return value from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
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,...

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.