Command e Parametri SALVARE






'Declare variables

Dim oCn As SqlConnection
Dim oCmd As SqlCommand
On Error GoTo ErrorHandler
'Create SqlConnection

oCn = New SqlConnection("Data Source=60016P05260;Initial Catalog=MAGAZZINO;Integrated Security=True")
oCmd = New SqlCommand
If (TxtId.Text.Equals("")) Then
'Create Sql String with parameter @SelectedLP

strSql = "Insert Into Articoli (Articolo) " + _
"Values(@Articolo)"
'add parameter Articolo

oCmd.Parameters.AddWithValue("@Articolo", TxtArticolo.Text)
Else
'Create Sql String with parameter @SelectedLP

strSql = "Update Articoli Set Articolo = @Articolo " + _
"Where Id = @Id"
'add parameter Articolo

oCmd.Parameters.AddWithValue("@Articolo", TxtArticolo.Text)
'add parameter Id

oCmd.Parameters.AddWithValue("@Id", TxtId.Text)
End If
'open connection

oCn.Open()
'Set connection to command

oCmd.Connection = oCn
'set Sql string to command object

oCmd.CommandText = strSql
'exexute command

oCmd.ExecuteNonQuery()
'close connection

oCn.Close()
'destroy objects

oCmd = Nothing
oCn = Nothing
FrmBranch_Load(Nothing, Nothing)
Exit Sub
ErrorHandler:
MsgBox("A problem occurred and the application can not recover! " + _
"Please contact the technical support.")
Err.Clear()










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