Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How do I pass a parameter value from my VB code in

Author  Topic 

arraysys
Starting Member

12 Posts

Posted - 2010-10-14 : 04:12:46
How do I pass a parameter value from my VB code into my SQL stored procedure?

EXAMPLE:
in my winform code behind (VB.NET) I have an integer value 'ProdId' from a selectedIndex in a datagridviewcombobox

I need to pass this value to my stored procedure as the parameter value of my stored procedure.



Array

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-14 : 04:30:44
Check the link. It may be of some help to you.
http://www.codeproject.com/KB/vbscript/simple_sp_vb6.aspx
Go to Top of Page

arraysys
Starting Member

12 Posts

Posted - 2010-10-14 : 06:09:57
thanks - will try

Array
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-14 : 06:16:20
quote:
Originally posted by arraysys

How do I pass a parameter value from my VB code into my SQL stored procedure?

EXAMPLE:
in my winform code behind (VB) I have an integer value 'ProdId' from a selectedIndex in a datagridviewcombobox

I need to pass this value to my stored procedure as the parameter value of my stored procedure.



Array



Are you sure it is VB6 & not VB.NET?
because most of the developers tend to refer to VB.Net as VB.So its quite misunderstanding.

PBUH

Go to Top of Page

arraysys
Starting Member

12 Posts

Posted - 2010-10-14 : 07:17:35
VB.NET in VS2008

EXAMPLE:
in my winform code behind (VB) I have an integer value 'ProdId' from a selectedIndex in a datagridviewcombobox

I need to pass this value to my stored procedure as the parameter value of my stored procedure.



Array
[/quote]

Are you sure it is VB6 & not VB.NET?
because most of the developers tend to refer to VB.Net as VB.So its quite misunderstanding.

PBUH


[/quote]

Array
Go to Top of Page

arraysys
Starting Member

12 Posts

Posted - 2010-10-14 : 07:27:34
he code in the example is for VB6 so commands do not exist in VB.NET - do you know of any other source for this requirement of mine - thanks again

Array
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-14 : 07:51:00
quote:
Originally posted by arraysys

he code in the example is for VB6 so commands do not exist in VB.NET - do you know of any other source for this requirement of mine - thanks again

Array



Try this:
http://www.a1vbcode.com/snippet-3030.asp


Below is code extract from:
http://www.developer.com/net/vb/article.php/1562531/Programming-with-Stored-Procedures-in-Visual-Basic-NET-Part-2

Imports System.Data
2: Imports System.Data.SqlClient
3: Imports System.Configuration
4:
5: Public Class Form1
6: Inherits System.Windows.Forms.Form
7:
8: [ Windows Form Designer generated code ]
9:
10: Private Sub Form1_Load(ByVal sender As Object, _
11: ByVal e As System.EventArgs) Handles MyBase.Load
12:
13: InputParameter()
14:
15: End Sub
16:
17: Public Sub InputParameter()
18:
19: Dim Connection As SqlConnection = _
20: New SqlConnection( _
21: ConfigurationSettings.AppSettings( _
22: "ConnectionString"))
23:
24: Dim Command As SqlCommand = _
25: New SqlCommand()
26: Command.Connection = Connection
27: Command.CommandText = "CustOrderHist"
28: Command.CommandType = CommandType.StoredProcedure
29:
30: Dim Parameter As SqlParameter = _
31: New SqlParameter("@CustomerID", "ALFKI")
32: Parameter.Direction = ParameterDirection.Input
33: Parameter.DbType = DbType.String
34:
35: Command.Parameters.Add(Parameter) --Parameter added for sp
36:
37: Dim Adapter As SqlDataAdapter = _
38: New SqlDataAdapter(Command)
39:
40: Dim DataSet As DataSet = _
41: New DataSet("Order History")
42:
43: Adapter.Fill(DataSet)
44: DataGrid1.DataSource = DataSet.Tables(0)
45:
46: End Sub
47: End Class
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-14 : 08:02:21
I have no clue about vb.net but maybe this is helpful (VB.net):
http://www.vbforums.com/showthread.php?t=587567


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-14 : 08:03:10
Oh! I am a little late...



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

arraysys
Starting Member

12 Posts

Posted - 2010-10-14 : 08:29:29
problem solved thanks

code needed was cmd.parameters.AddWithValue() as opposed to Add()

Array
Go to Top of Page
   

- Advertisement -