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 'add parameter Articolo strSql = "Delete Articoli Where Id = @Id" oCmd.Parameters.AddWithValue("@Id", TxtId.Text) '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() |