ðHgeocities.com/SoHo/Gallery/3793/Form1.vb.htmgeocities.com/SoHo/Gallery/3793/Form1.vb.htmdelayedxqoÔJÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈÀ+Ëæ>OKtext/htmlÐÄjæ>ÿÿÿÿb‰.HWed, 04 Feb 2004 15:40:12 GMTÃ Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)en, *qoÔJæ>


Imports System.Data.OleDb
Imports System.Data
Imports System.Collections
Imports System.Text



Public Class Form1
    Inherits System.Windows.Forms.Form


Dim Conn As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=C:\\Teste.mdb")
Dim Leitura As OleDbDataReader


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
    Friend WithEvents Inserir As System.Windows.Forms.Button
    Friend WithEvents AberturaDB As System.Windows.Forms.Button
    Friend WithEvents ProximoReg As System.Windows.Forms.Button
    Friend WithEvents CloseDB As System.Windows.Forms.Button
    Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
    Friend WithEvents CarregaCombo As System.Windows.Forms.Button
    Friend WithEvents DataSis As System.Windows.Forms.TextBox
    Friend WithEvents DelReg As System.Windows.Forms.Button
    Friend WithEvents Atualiza As System.Windows.Forms.Button
    Friend WithEvents LeituraLote As System.Windows.Forms.Button
     Private Sub InitializeComponent()
        Me.ProximoReg = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.CloseDB = New System.Windows.Forms.Button
        Me.Label4 = New System.Windows.Forms.Label
        Me.TextBox4 = New System.Windows.Forms.TextBox
        Me.Inserir = New System.Windows.Forms.Button
        Me.AberturaDB = New System.Windows.Forms.Button
        Me.ComboBox1 = New System.Windows.Forms.ComboBox
        Me.CarregaCombo = New System.Windows.Forms.Button
        Me.DataSis = New System.Windows.Forms.TextBox
        Me.DelReg = New System.Windows.Forms.Button
        Me.Atualiza = New System.Windows.Forms.Button
        Me.LeituraLote = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'ProximoReg
        '
        Me.ProximoReg.Location = New System.Drawing.Point(448, 216)
        Me.ProximoReg.Name = "ProximoReg"
        Me.ProximoReg.Size = New System.Drawing.Size(160, 40)
        Me.ProximoReg.TabIndex = 0
        Me.ProximoReg.Text = "Proximo"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(192, 56)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(168, 20)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = ""
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(192, 80)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(168, 20)
        Me.TextBox2.TabIndex = 2
        Me.TextBox2.Text = ""
        '
        'TextBox3
        '
        Me.TextBox3.Location = New System.Drawing.Point(192, 104)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(168, 20)
        Me.TextBox3.TabIndex = 3
        Me.TextBox3.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(80, 56)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(96, 24)
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "Numero"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(80, 104)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96, 24)
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "Idade"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(80, 80)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(96, 24)
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "Nome"
        '
        'CloseDB
        '
        Me.CloseDB.Location = New System.Drawing.Point(448, 256)
        Me.CloseDB.Name = "CloseDB"
        Me.CloseDB.Size = New System.Drawing.Size(160, 32)
        Me.CloseDB.TabIndex = 7
        Me.CloseDB.Text = "Close"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(80, 128)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(96, 24)
        Me.Label4.TabIndex = 8
        Me.Label4.Text = "Data"
        '
        'TextBox4
        '
        Me.TextBox4.Location = New System.Drawing.Point(192, 136)
        Me.TextBox4.Name = "TextBox4"
        Me.TextBox4.Size = New System.Drawing.Size(168, 20)
        Me.TextBox4.TabIndex = 9
        Me.TextBox4.Text = ""
        '
        'Inserir
        '
        Me.Inserir.Location = New System.Drawing.Point(32, 184)
        Me.Inserir.Name = "Inserir"
        Me.Inserir.Size = New System.Drawing.Size(152, 32)
        Me.Inserir.TabIndex = 10
        Me.Inserir.Text = "Insert"
        '
        'AberturaDB
        '
        Me.AberturaDB.Location = New System.Drawing.Point(448, 176)
        Me.AberturaDB.Name = "AberturaDB"
        Me.AberturaDB.Size = New System.Drawing.Size(160, 40)
        Me.AberturaDB.TabIndex = 11
        Me.AberturaDB.Text = "Abertura DB"
        '
        'ComboBox1
        '
        Me.ComboBox1.Location = New System.Drawing.Point(448, 48)
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
        Me.ComboBox1.TabIndex = 12
        Me.ComboBox1.Text = "ComboBox1"
        '
        'CarregaCombo
        '
        Me.CarregaCombo.Location = New System.Drawing.Point(448, 96)
        Me.CarregaCombo.Name = "CarregaCombo"
        Me.CarregaCombo.Size = New System.Drawing.Size(136, 32)
        Me.CarregaCombo.TabIndex = 13
        Me.CarregaCombo.Text = "Carrega Combo"
        '
        'DataSis
        '
        Me.DataSis.Location = New System.Drawing.Point(32, 216)
        Me.DataSis.Name = "DataSis"
        Me.DataSis.Size = New System.Drawing.Size(152, 20)
        Me.DataSis.TabIndex = 14
        Me.DataSis.Text = ""
        '
        'DelReg
        '
        Me.DelReg.Location = New System.Drawing.Point(184, 184)
        Me.DelReg.Name = "DelReg"
        Me.DelReg.Size = New System.Drawing.Size(152, 32)
        Me.DelReg.TabIndex = 15
        Me.DelReg.Text = "Del Registro"
        '
        'Atualiza
        '
        Me.Atualiza.Location = New System.Drawing.Point(184, 216)
        Me.Atualiza.Name = "Atualiza"
        Me.Atualiza.Size = New System.Drawing.Size(152, 32)
        Me.Atualiza.TabIndex = 16
        Me.Atualiza.Text = "Atualiza"
        '
        'LeituraLote
        '
        Me.LeituraLote.Location = New System.Drawing.Point(200, 312)
        Me.LeituraLote.Name = "LeituraLote"
        Me.LeituraLote.Size = New System.Drawing.Size(240, 32)
        Me.LeituraLote.TabIndex = 17
        Me.LeituraLote.Text = "Leitura em Lote"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(664, 365)
        Me.Controls.Add(Me.LeituraLote)
        Me.Controls.Add(Me.Atualiza)
        Me.Controls.Add(Me.DelReg)
        Me.Controls.Add(Me.DataSis)
        Me.Controls.Add(Me.CarregaCombo)
        Me.Controls.Add(Me.ComboBox1)
        Me.Controls.Add(Me.AberturaDB)
        Me.Controls.Add(Me.Inserir)
        Me.Controls.Add(Me.TextBox4)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.CloseDB)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.ProximoReg)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    
    Private Sub ProximoReg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProximoReg.Click
        ' Always call Read before accessing data.


If Leitura.Read() <> 0 Then
TextBox1.Text = Leitura("Numero").ToString()
TextBox2.Text = Leitura("Nome").ToString()
TextBox3.Text = Leitura("idade").ToString()
TextBox4.Text = Leitura("Data").ToString()
Else
MessageBox.Show("Fim de Leitura")
End If



    End Sub

    Private Sub CloseDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseDB.Click


Leitura.Close()
Conn.Close()

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


DataSis.Text = DateTime.Now.ToString("dd/MM/yyyy")

    End Sub

    Private Sub Inserir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Inserir.Click


Dim Comando As New OleDbCommand("Insert into teste (nome,idade,data) values ('" + TextBox2.Text + "'," + TextBox3.Text + ",'" + TextBox4.Text + "')")
Comando.Connection = Conn
Try
Conn.Open()
Comando.ExecuteNonQuery()
Conn.Close()
MessageBox.Show("Registro garvado OK")
Catch Err As Exception
MessageBox.Show(Err.ToString())
Throw New System.Exception("Erro de Insert")
End Try

    End Sub

    Private Sub AberturaDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AberturaDB.Click


Dim Comando As New OleDbCommand("select * from teste", Conn)
Try
Conn.Open()
Leitura = Comando.ExecuteReader(CommandBehavior.CloseConnection)
Catch err As Exception
MessageBox.Show(err.ToString())
Throw New System.Exception("Erro de select")
Finally

End Try

    End Sub


    Private Sub CarregaCombo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CarregaCombo.Click


Dim listaNome As New ArrayList
Try
While Leitura.Read()
listaNome.Add(Leitura("Nome").ToString())
End While
ComboBox1.DataSource = listaNome
Catch Err As Exception
MessageBox.Show(Err.ToString())
Throw New System.Exception("Erro de Carga no cambo Box")
Finally

End Try

    End Sub

    Private Sub DelReg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DelReg.Click


Dim Comando As New OleDbCommand("Delete from Teste where numero=" + TextBox1.Text)
Comando.Connection = Conn
Try
Conn.Open()
Comando.ExecuteNonQuery()
Conn.Close()
MessageBox.Show("Registro garvado OK")
Catch Err As Exception

MessageBox.Show(Err.ToString())
Throw New System.Exception("Erro de Delete")
Finally
Conn.Close()
End Try

    End Sub

    Private Sub Atualiza_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Atualiza.Click


Dim Comando As New OleDbCommand("UPDate Teste set Nome='" + TextBox2.Text + "' where numero=" & TextBox1.Text)
Comando.Connection = Conn
Try
Conn.Open()
Comando.ExecuteNonQuery()
Conn.Close()
MessageBox.Show("Registro garvado OK")
Catch Err As Exception

MessageBox.Show(Err.ToString())
Throw New System.Exception("Erro de UPDate")
Finally
Conn.Close()
End Try

    End Sub


    Private Sub LeituraLote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeituraLote.Click


Dim Adp As New OleDbDataAdapter("select * from teste", "Provider=Microsoft.Jet.Oledb.4.0; Data Source=C:\\Teste.mdb")
Dim listaNome As New ArrayList
Dim dt As DataSet = New DataSet
Dim linha As DataRow
'datagrid1.datasource=dt
Adp.Fill(dt, "teste")

While Leitura.Read()
Dim cpo As New ArrayList
cpo.Add(Leitura("nome"))
listaNome.Add(cpo)
End While

For i As Integer = 1 To listaNome.Count


Next

    End Sub
End Class