segunda-feira, 19 de setembro de 2011

on

Public Class Form1

    Private Const CONNECTION_STRING = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\BD\Cadastro.accdb"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim catalogo As New ADOX.Catalog
        Try
            catalogo.Create(CONNECTION_STRING)
            MessageBox.Show("Banco criado com sucesso!")
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim conn As New OleDb.OleDbConnection(CONNECTION_STRING)
        Dim cmd As New OleDb.OleDbCommand("CREATE TABLE Contato (ID int not null, Nome varchar(50))", conn)
        conn.Open()
        cmd.ExecuteNonQuery()
        MessageBox.Show("Tabela 'Contato' criada com sucesso!")
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim conn As New OleDb.OleDbConnection(CONNECTION_STRING)
        Dim cmd As New OleDb.OleDbCommand()

        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        conn.Open()

        cmd.CommandText = "INSERT INTO Contato VALUES (1, 'Contato 1')"
        cmd.ExecuteNonQuery()

        cmd.CommandText = "INSERT INTO Contato VALUES (2, 'Contato 2')"
        cmd.ExecuteNonQuery()

        cmd.CommandText = "INSERT INTO Contato VALUES (3, 'Contato 3')"
        cmd.ExecuteNonQuery()
        MessageBox.Show("Registros inseridos com sucesso!")
    End Sub
End Class

 Espero ter ajudado e até mais!!!


0 comentários:

Postar um comentário