Passing Parameters

Pass Parameter to SQL Stored procedure from VB
Create Stored Procedure in SQL Server
Create Proc [dbo].[PassP]
@Id smallint
as
Select * from dbo.Customers where Id=@Id
Visual Basic
Dim sqlcnn As New ADODB.Connection
Dim cmd As ADODB.Command
sqlcnn.ConnectionString = “Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security 
Info=False;Initial Catalog=Test;Data Source=server”
sqlcnn.Open
sqlcnn.CommandTimeout = 120
 Set cmd = New ADODB.Command
 cmd.ActiveConnection = sqlcnn
 cmd.CommandType = adCmdStoredProc
 cmd.CommandText = “dbo.PassP”
 cmd.Parameters.Append cmd.CreateParameter(“custId”, adInteger, adParamInput, 6, 
Combo1.ItemData(Combo1.ListIndex))
 cmd.Execute
 Set cmd.ActiveConnection = Nothing

Leave a Reply

Your email address will not be published. Required fields are marked *