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

Sending Parameter to Stored Procedure from ComboBox and getting the returned data fro

I have written a little vb code to try to run a stored procedure, take the parameter @serialnumber and feed it to the S-proc. Then take the field transactionnumber and populate textbox1.text with it on the form. Simple task, but I am a newb to this. Any help is appreciated. please find Sproc and vb form code below. Currently, it returns a 0 in the text box. I've tested against sql running the sproc and get expected data. So the sproc isn't the issue. It's my gimpy ability to write code lol. If there is a better language to do this in, please feel free to chime in. I'm not a sissy when it comes to criticism :)

Expand|Select|Wrap|Line Numbers
  1. USE [EMP_RMS_POS]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[Serial_Lookup]    Script Date: 12/05/2013 17:51:18 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROCEDURE [dbo].[Serial_Lookup] 
  9. @serialnumber as varchar(20)
  10. AS
  11. BEGIN
  12.     SET NOCOUNT ON;
  13. select  [Transaction].TransactionNumber , Serial.SerialNumber
  14. FROM         Serial INNER JOIN
  15.                       [Transaction] ON Serial.TransactionEntryID = [Transaction].TransactionNumber
  16. where SerialNumber = @serialnumber
  17. END
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2.         Dim cn As New SqlConnection("server=localhost;database=emp_rms_pos;integrated security=true")
  3.         Dim cmd As New SqlCommand
  4.         cmd.Connection = cn
  5.         cn.Open()
  6.         cmd.CommandText = "serial_lookup"
  7.         cmd.CommandType = CommandType.StoredProcedure
  8.         cmd.Parameters.Add(New SqlParameter("transactionnumber", SqlDbType.Int))
  9.         cmd.Parameters("transactionnumber").Direction = ParameterDirection.ReturnValue
  10.         cmd.Parameters.Add(New SqlParameter("@serialnumber", SqlDbType.VarChar, 20)).Value = ComboBox1.Text
  11.         cmd.Parameters("@serialnumber").Direction = ParameterDirection.Input
  12.         Dim result As SqlDataReader = cmd.ExecuteReader
  13.         cn.Close()
  14.         TextBox1.Text = cmd.Parameters("transactionnumber").Value
  15.     End Sub
  16. End Class
This has to be something silly and stupid :) Any help is much appreciated guys. My background is infrastructure (Servers/Networking for 20+ years) So this is new ground for me.
Dec 6 '13 #1
1 3107
Frinavale
9,735 Expert Mod 8TB
You called the ExecuteReader command but you failed to actually read the results.

Check out the MSDN documentation for the ExecuteReader method.

You should also consider using "using blocks" to manage the cleanup of your connections etc.
Expand|Select|Wrap|Line Numbers
  1. Using cn As New SqlConnection("server=localhost;database=emp_rms_pos;integrated security=true")
  2.   Using cmd As New SqlCommand(cn)
  3.       cmd.CommandText = "serial_lookup"
  4.       cmd.CommandType = CommandType.StoredProcedure
  5.       cmd.Parameters.Add(New SqlParameter("transactionnumber", SqlDbType.Int))
  6.       cmd.Parameters("transactionnumber").Direction = ParameterDirection.ReturnValue
  7.       cmd.Parameters.Add(New SqlParameter("@serialnumber", SqlDbType.VarChar, 20)).Value = ComboBox1.Text
  8.       cmd.Parameters("@serialnumber").Direction = ParameterDirection.Input
  9.  
  10.       cn.Open()
  11.       Dim result As SqlDataReader = cmd.ExecuteReader()
  12.  
  13.       If result.HasRows Then
  14.         While reader.Read()
  15.           TextBox1.Text = result("TransactionNumber")
  16.         End While
  17.       End If
  18.  
  19.   End Using
  20. End Using
Dec 10 '13 #2

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

Similar topics

1
by: sbh | last post by:
I need to copy data from a table on one Oracle server to another. Scenario: Need to create a stored procedure in server a, database aa that will copy data from server b, database bb, table bbb to...
15
by: Philip Mette | last post by:
I am begginner at best so I hope someone that is better can help. I have a stored procedure that updates a view that I wrote using 2 cursors.(Kind of a Inner Loop) I wrote it this way Because I...
0
by: VictorCorey | last post by:
Is it possible to use a multi-parameter query in .NET Here's the method Public Function SearchCatalog(ByVal searchString As String, ByVal allWords As String) As OleDbDataReade ' Create the...
2
by: alex.mcshane | last post by:
Hi - I would be grateful for any knowledge regarding the following. Whilst QAing Stored Procedures developed by colleagues, I noticed the following 'superflous' parameter specifications:- 1)...
0
by: Howard Carr | last post by:
I have a stored procedure that I want to add to my data set. I've followed the procedures to do this - open server connection, go to stored procedure tab and drag procedure onto design form. The...
2
by: andres | last post by:
hi all, thanks for everyone for your support! i have a report being built in studio 2005. It calls a stored procedure. The SP runs a query and gets a data set which then loops through to get...
3
by: itarunachalam | last post by:
Hi friends, I have a table structure like this in SQL sever 2000. i want a stored procedure to transfer the data from "tblSurvey" table to "tblRespondent" table. Table - tblSurvey...
2
by: crazyfisher | last post by:
> Dear all, > I am trying to write a stored procedure for a recipe database so that the > user can choose how many recipes from what category. > I have written this one to get 7 recipes from...
1
by: seyyadri | last post by:
Hi, I want the data in excel, pulled from SQL server stored procedure. The SQL SP has the parameters. when we open/refresh the excel it should prompt the user to enter the parameters (dynamically),...
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
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
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...
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
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...

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.