quinta-feira, 6 de setembro de 2012

on

Imports System.Data.OleDb

Public Class frmSQL
    Inherits System.Windows.Forms.Form

    Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
                                                      Replace(Application.StartupPath, "bin", "") & _
                                                      "Cadastro.mdb;Mode=ReadWrite;Persist Security Info=False")


    Private Sub ExecuteBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExecuteBtn.Click

        Dim DataSet As New DataSet
        Dim DataTable As New DataTable()

        'Declara a OleDbCommand Object
        Dim cmd As New System.Data.OleDb.OleDbCommand(txtSqlClientes.Text, conn)
        Dim DataAdapter As New OleDbDataAdapter(txtSqlClientes.Text, conn)

        Try
            Select Case UCase(Mid(Trim(txtSqlClientes.Text), 1, 6))
                Case "SELECT"
                    conn.Open()
                    cmd.ExecuteNonQuery()
                    DataAdapter.Fill(DataTable)
                    Me.DgViewClientes.DataSource = DataTable
                    conn.Close()

                Case "INSERT"
                    conn.Open()
                    cmd.ExecuteNonQuery()                   
                    conn.Close()
                    MsgBox("Registro inserido com sucesso.", MsgBoxStyle.Exclamation)

                Case "UPDATE"
                    conn.Open()
                    cmd.ExecuteNonQuery()                   
                    conn.Close()
                    MsgBox("Registro alterado com sucesso.", MsgBoxStyle.Exclamation)

                Case "DELETE"
                    conn.Open()
                    cmd.ExecuteNonQuery()                                    
                    conn.Close()
                    MsgBox("Registro deletado com sucesso.", MsgBoxStyle.Exclamation)

            End Select

        Catch ex As Data.OleDb.OleDbException
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Dim DataSet As New DataSet
        Dim DataTable As New DataTable()

        'Declara a OleDbCommand Object
        Dim cmd As New System.Data.OleDb.OleDbCommand(txtSqlGrupos.Text, conn)
        Dim DataAdapter As New OleDbDataAdapter(txtSqlGrupos.Text, conn)

        Try
            Select Case UCase(Mid(Trim(txtSqlGrupos.Text), 1, 6))
                Case "SELECT"
                    conn.Open()
                    cmd.ExecuteNonQuery()
                    DataAdapter.Fill(DataTable)
                    Me.DgviewGrupos.DataSource = DataTable
                    conn.Close()

                Case "INSERT"
                    conn.Open()
                    cmd.ExecuteNonQuery()                                    
                    conn.Close()
                    MsgBox("Registro inserido com sucesso.", MsgBoxStyle.Exclamation)                   

                Case "UPDATE"
                    conn.Open()
                    cmd.ExecuteNonQuery()                                       
                    conn.Close()
                    MsgBox("Registro alterado com sucesso.", MsgBoxStyle.Exclamation)

                Case "DELETE"
                    conn.Open()
                    cmd.ExecuteNonQuery()                                       
                    conn.Close()
                    MsgBox("Registro deletado com sucesso.", MsgBoxStyle.Exclamation)

            End Select

        Catch ex As Data.OleDb.OleDbException
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub btnQuerys_Click(sender As System.Object, e As System.EventArgs) Handles btnQuerys.Click
        frmQuerys.ShowDialog()
    End Sub
End Class






Public Class frmQuerys

    Private Sub btnConcluir_Click(sender As System.Object, e As System.EventArgs) Handles btnConcluir.Click

        If Me.RadioButton1.Checked Then
            frmSQL.txtSqlClientes.Text = RadioButton1.Text
        End If

        If Me.RadioButton2.Checked Then
            frmSQL.txtSqlClientes.Text = RadioButton2.Text
        End If

        If Me.RadioButton3.Checked Then
            frmSQL.txtSqlClientes.Text = RadioButton3.Text
        End If

        If Me.RadioButton4.Checked Then
            frmSQL.txtSqlGrupos.Text = RadioButton4.Text
        End If

        If Me.RadioButton5.Checked Then
            frmSQL.txtSqlGrupos.Text = RadioButton5.Text
        End If

        If Me.RadioButton6.Checked Then
            frmSQL.txtSqlGrupos.Text = RadioButton6.Text
        End If

        Me.Dispose()

    End Sub
End Class

Pegue o projeto neste link: http://www.mediafire.com/?3iinrpjc9mz194p

Espero ter ajudado... Abraços e até a próxima!

0 comentários:

Postar um comentário