Advertisement
username_leta

inserir base dados acess

Apr 13th, 2019
140
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 = "INSERT INTO Clientes([Nome], [Empresa]) VALUES (@Nome, @Empresa)"
  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.  
  9. ConnectionString.Open()
  10.  
  11. Dim x As Integer = command.ExecuteNonQuery()
  12.  
  13. If x < 1 Then
  14.      MessageBox.Show("Erro ao inserir", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
  15. Else
  16.      MessageBox.Show("Registo inserido com sucesso!", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
  17. End If
  18.  
  19. ConnectionString.Close()
  20. command = Nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement