4.3 Scrivere Dati con VBA

Creare, modificare e cancellare record.

Inserire Nuovo Record

Sub NuovoCliente()
    Dim http As Object
    Dim url As String
    Dim body As String
 
    url = "http://localhost:5000/api/v1/dsn/demo/tables/Customers"
    body = "{""Name"":""Nuova Azienda Srl"",""Country"":""Italy""}"
 
    Set http = CreateObject("MSXML2.XMLHTTP")
    http.Open "POST", url, False
    http.setRequestHeader "Content-Type", "application/json"
    http.send body
 
    If http.Status = 200 Then
        MsgBox "Creato con successo!"
    Else
        MsgBox "Errore: " & http.responseText
    End If
End Sub

Aggiornare Record

Sub AggiornareCliente()
    Dim body As String
    body = "{""primaryKey"":{""Id"":42},""fields"":{""Name"":""Aggiornato""}}"
 
    http.Open "PUT", url, False
    http.setRequestHeader "Content-Type", "application/json"
    http.send body
End Sub

Eliminare Record

Sub EliminareCliente()
    http.Open "DELETE", url & "?Id=42", False
    http.send
End Sub
Zuletzt geändert: il 29/01/2026 alle 23:25