Command parameters su store procedure






' ****** creazione store procedure *********

USE [pubs]
GO
/****** Oggetto: StoredProcedure [dbo].[p_sel_autore] Data script: 08/07/2008 11:22:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[NomeAutore] (@au_Lname varchar) AS SELECT * FROM authors WHERE au_Lname = @au_Lname ;
GO


' ****** Modifica store procedure *********

USE [pubs]
GO
/****** Oggetto: StoredProcedure [dbo].[NomeAutore] Data script: 08/07/2008 11:31:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[NomeAutore] (@au_Lname varchar(40)) AS SELECT * FROM authors WHERE au_Lname = @au_Lname ;


' *****************************************************************************************************


Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms




' Create a connection object

Dim dbConn As New SqlConnection( _
"server=(local); database=pubs; integrated security=true")
dbConn.Open()

Dim cmd As New SqlCommand()

cmd.CommandText = "NomeAutore"
cmd.CommandType = System.Data.CommandType.StoredProcedure

cmd.Connection = dbConn
cmd.Parameters.Add(New SqlParameter("@au_Lname", SqlDbType.Char, 40, "au_Lname"))

Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet("Author")
da.SelectCommand.Parameters(0).Value = "Gringlesby"
da.Fill(ds)

If Not ds Is Nothing Then
If ds.Tables(0).Rows.Count <> 0 Then
MessageBox.Show("Hi, author: " & _
ds.Tables(0).Rows(0)("au_lname").ToString() & " ....Found() HE!HE!HE!")
End If

End If










( commandparameterssustoreprocedure.html )- by Paolo Puglisi - Modifica del 17/12/2023