SHARE
TWEET

inserir base dados acess

username_leta Apr 13th, 2019 (edited) 106 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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top