Advertisement
username_leta

Update base dados acess

Apr 13th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim ConnectionString As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "pedro..accdb")
  2. Dim query As String = "UPDATE Clientes SET [Nome] = @Nome, [Empresa] = @Empresa WHERE ID = @IDCliente"
  3.  
  4. Dim command As New OleDbCommand(query, ConnectionString)
  5.  
  6. command.Parameters.Add("@Nome", OleDbType.VarChar).Value = NomeTextbox.Text
  7. command.Parameters.Add("@Empresa", OleDbType.VarChar).Value = EmpresaTextbox.Text
  8. ' Actualiza apenas os dados do cliente que consta na Textbox
  9. command.Parameters.Add("@IDCliente", OleDbType.Integer).Value = IDClienteTextbox.Text  
  10.  
  11. ConnectionString.Open()
  12.  
  13. Dim x As Integer = command.ExecuteNonQuery()
  14.  
  15. If x < 1 Then
  16.      MessageBox.Show("Erro ao actualizar", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
  17. Else
  18.      MessageBox.Show("Actualizado com sucesso!", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
  19. End If
  20.  
  21. ConnectionString.Close()
  22. command = Nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement