Torna al Thread

Imports System.Data.SqlClient Module Module1 Sub Main() Dim cn As New SqlConnection("Data Source=.;Initial Catalog=tempdb;Integrated Security=SSPI") Dim cmd As New SqlCommand("up_AddStudent", cn) With cmd ' Definisco il Command Type .CommandType = CommandType.StoredProcedure ' Definisco i parametri di input .Parameters.Add(New SqlParameter("@FirstName", SqlDbType.VarChar, 10)) .Parameters("@FirstName").Value = "Lorenzo" .Parameters.Add(New SqlParameter("@LastName", SqlDbType.VarChar, 10)) .Parameters("@LastName").Value = "Benaglia" ' Definisco il parametro di output Dim p As SqlParameter p = .Parameters.Add(New SqlParameter("@NewID", SqlDbType.Int, 4)) p.Direction = ParameterDirection.Output ' Apro la connessione ed eseguo la query .Connection.Open() .ExecuteNonQuery() MsgBox("NewID: " & .Parameters("@NewID").Value.ToString) End With cn.Close() End Sub
Copyright © 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5