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.
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 datagridviewcomboboxI 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 |
 |
|
arraysys
Starting Member
12 Posts |
Posted - 2010-10-14 : 06:09:57
|
thanks - will tryArray |
 |
|
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 datagridviewcomboboxI 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 |
 |
|
arraysys
Starting Member
12 Posts |
Posted - 2010-10-14 : 07:17:35
|
VB.NET in VS2008EXAMPLE:in my winform code behind (VB) I have an integer value 'ProdId' from a selectedIndex in a datagridviewcomboboxI 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 |
 |
|
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 againArray |
 |
|
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 againArray
Try this:http://www.a1vbcode.com/snippet-3030.aspBelow is code extract from:http://www.developer.com/net/vb/article.php/1562531/Programming-with-Stored-Procedures-in-Visual-Basic-NET-Part-2Imports System.Data2: Imports System.Data.SqlClient3: Imports System.Configuration4: 5: Public Class Form16: Inherits System.Windows.Forms.Form7: 8: [ Windows Form Designer generated code ]9: 10: Private Sub Form1_Load(ByVal sender As Object, _11: ByVal e As System.EventArgs) Handles MyBase.Load12: 13: InputParameter()14: 15: End Sub16: 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 = Connection27: Command.CommandText = "CustOrderHist"28: Command.CommandType = CommandType.StoredProcedure29: 30: Dim Parameter As SqlParameter = _31: New SqlParameter("@CustomerID", "ALFKI")32: Parameter.Direction = ParameterDirection.Input33: Parameter.DbType = DbType.String34: 35: Command.Parameters.Add(Parameter) --Parameter added for sp36: 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 Sub47: End Class |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
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. |
 |
|
arraysys
Starting Member
12 Posts |
Posted - 2010-10-14 : 08:29:29
|
problem solved thankscode needed was cmd.parameters.AddWithValue() as opposed to Add()Array |
 |
|
|
|
|