Konu 33: veritabani, modül ve vt işlemleri, iki tabloda işlem, vt'den sorgu çağırma(rapor)

Örnek Uygulama

Ekran Görüntüsü

 

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        baglanti = New OleDb.OleDbConnection("Provider=Microsoft.Jet.oledb.4.0;Data Source=" & Application.StartupPath & "\vt1.mdb")

    End Sub

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

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        musteri.Show()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        satis.Show()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        rapor.Show()
    End Sub
End Class

Ekran Görüntüsü

 

Public Class urun
    Dim secilen As Integer
    Private Sub urun_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'verileri goster
        DataGridView1.DataSource = goster("select * from urun").Tables("tablo")

    End Sub

    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        secilen = DataGridView1.Rows(e.RowIndex).Cells(0).Value

        TextBox8.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
        TextBox7.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value
        TextBox6.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
        TextBox5.Text = DataGridView1.Rows(e.RowIndex).Cells(4).Value
        TextBox14.Text = DataGridView1.Rows(e.RowIndex).Cells(6).Value

        Label1.Text = secilen
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim para As String = Replace(TextBox4.Text, ",", ".")
        If IsNumeric(para) = False Then
            MsgBox("para birimini hatalı girdiniz")
            Exi t Sub
        End If
        Dim para1 As String = Replace(TextBox3.Text, ",", ".")
        If IsNumeric(para1) = False Then
            MsgBox("para birimini hatalı girdiniz")
            Exi t Sub
        End If

        Dim sql As String = "insert into urun (barkod,ad,alis,satis,tarih,adet) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & para1 & "'," & para & ",'" & Now.Date & "'," & Val(TextBox13.Text) & ")"
        calistir(sql)

        DataGridView1.DataSource = goster("select * from urun").Tables("tablo")

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim para As String = Replace(TextBox6.Text, ",", ".")
        If IsNumeric(para) = False Then
            MsgBox("para birimini hatalı girdiniz")
            Exi t Sub
        End If
        Dim para1 As String = Replace(TextBox5.Text, ",", ".")
        If IsNumeric(para1) = False Then
            MsgBox("para birimini hatalı girdiniz")
            Exi t Sub
        End If
        Dim sql As String = "update urun set barkod='" & TextBox8.Text & "',ad='" & TextBox7.Text & "',alis=" & para & ",satis=" & para1 & ",tarih='" & Now.Date & "',adet=" & Val(TextBox14.Text) & " where sira_no=" & secilen
        calistir(sql)
        DataGridView1.DataSource = goster("select * from urun").Tables("tablo")

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim sql As String = "delete from urun where sira_no=" & secilen
        calistir(sql)

        DataGridView1.DataSource = goster("select * from urun").Tables("tablo")
    End Sub

    Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged, TextBox11.TextChanged, TextBox10.TextChanged, TextBox9.TextChanged, TextBox15.TextChanged, DateTimePicker1.ValueChanged

        Dim sql As String = "select * from urun where "
        If CheckBox1.Checked Then
            sql &= "barkod like '%" & TextBox12.Text & "%' and "
        End If
        If CheckBox2.Checked Then
            sql &= "ad like '%" & TextBox11.Text & "%' and "
        End If
        If CheckBox3.Checked Then
            sql &= "alis like '%" & TextBox10.Text & "%' and "
        End If
        If CheckBox4.Checked Then
            sql &= "satis like %" & TextBox9.Text & "% and "
        End If
        If CheckBox5.Checked Then
            sql &= "adet like %" & TextBox9.Text & "% and "
        End If
        If CheckBox6.Checked Then
            Dim tar As Date = DateTimePicker1.Value
            Dim tarih As String = tar.Month & "/" & tar.Day & "/" & tar.Year
            sql &= "tarih =#" & tarih & "# and "
        End If

        If sql.EndsWith("and ") Then
            'son 4 karakteri sil
            sql = sql.Remove(sql.Length - 4, 4)
        ElseIf sql.EndsWith("where ") Then
            'son 6 karakteri sil
            sql = sql.Remove(sql.Length - 6, 6)
        End If

        DataGridView1.DataSource = goster(sql).Tables("tablo")
    End Sub

End Class

Ekran Görüntüsü

 

Public Class musteri
    Dim baglanti As OleDb.OleDbConnection
    Dim secilen As Integer
    Dim dt As DataTable

    Private Sub musteri_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dt = goster("select * from musteri").Tables("tablo")
        DataGridView1.DataSource = dt
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sql As String = "insert into musteri (ad,soyad,tel,adres) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
        calistir(sql)
        dt = goster("select * from musteri").Tables("tablo")
        DataGridView1.DataSource = dt
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
        Dim sql As String = "update musteri set ad='" & TextBox5.Text & "',soyad='" & TextBox6.Text & "',tel='" & TextBox7.Text & "',adres='" & TextBox8.Text & "' where sira_no=" & secilen
        calistir(sql)
        dt = goster("select * from musteri").Tables("tablo")
        DataGridView1.DataSource = dt
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim sql As String = "delete from musteri where sira_no=" & secilen
        calistir(sql)
        dt = goster("select * from musteri").Tables("tablo")
        DataGridView1.DataSource = dt
    End Sub
    Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged, TextBox11.TextChanged, TextBox10.TextChanged, TextBox9.TextChanged
        'Dim sql As String = "select * from kisiler where ad like '%a%' and soyad like '%a%' and tel like '%1%' and para like 1 and"
        Dim sql As String = "select * from musteri where "
        If CheckBox1.Checked Then
            sql &= "ad like '%" & TextBox12.Text & "%' and "
        End If
        If CheckBox2.Checked Then
            sql &= "soyad like '%" & TextBox11.Text & "%' and "
        End If
        If CheckBox3.Checked Then
            sql &= "tel like '%" & TextBox10.Text & "%' and "
        End If
        If CheckBox4.Checked Then
            sql &= "adres like %" & TextBox9.Text & "% and "
        End If

        If sql.EndsWith("and ") Then
            'son 4 karakteri sil
            sql = sql.Remove(sql.Length - 4, 4)
        ElseIf sql.EndsWith("where ") Then
            'son 6 karakteri sil
            sql = sql.Remove(sql.Length - 6, 6)
        End If

        dt = goster(sql).Tables("tablo")
        DataGridView1.DataSource = dt

    End Sub
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter

        secilen = DataGridView1.Rows(e.RowIndex).Cells(0).Value
        TextBox5.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
        TextBox6.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value
        TextBox7.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
        TextBox8.Text = DataGridView1.Rows(e.RowIndex).Cells(4).Value

        Label9.Text = secilen
    End Sub

End Class

Ekran Görüntüsü

 

Public Class satis
    Dim secUrun, secMusteri As Integer
    Dim satis_fiyati As Integer
    Dim adet As Integer
    Private Sub satis_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DataGridView1.DataSource = goster("select * from urun").Tables("tablo")
        DataGridView2.DataSource = goster("select * from musteri").Tables("tablo")
        DataGridView3.DataSource = goster("select * from satis").Tables("tablo")
    End Sub

    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        secUrun = DataGridView1.Rows(e.RowIndex).Cells(0).Value
        satis_fiyati = DataGridView1.Rows(e.RowIndex).Cells(4).Value
        adet = DataGridView1.Rows(e.RowIndex).Cells(6).Value
        Label1.Text = secUrun
    End Sub

    Private Sub DataGridView2_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.RowEnter
        secMusteri = DataGridView2.Rows(e.RowIndex).Cells(0).Value
        Label2.Text = secMusteri
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'satis tablosuna yeni kayıt

        Dim sql As String = "insert into satis (musteri_sira,urun_sira,satis,adet,tarih) values (" & secMusteri & "," & secUrun & "," & satis_fiyati & "," & Val(TextBox1.Text) & "," & Now.Date & ")"
        calistir(sql)
        DataGridView3.DataSource = goster("select * from satis").Tables("tablo")

        'urun tablosunda guncelleme
        Dim kalan As Integer = adet - Val(TextBox1.Text)
        sql = "update urun set adet=" & kalan & " where sira_no=" & secUrun
        calistir(sql)
        DataGridView1.DataSource = goster("select * from urun").Tables("tablo")
    End Sub
End Class
Module Module1
    Public baglanti As OleDb.OleDbConnection

    Public Function goster(ByVal sql As String) As DataSet
        Dim adaptor As New OleDb.OleDbDataAdapter(sql, baglanti)
        Dim ds As New DataSet
        adaptor.Fill(ds, "tablo")
        baglanti.Close()
        Return ds
    End Function

    Public Sub calistir(ByVal sql As String)
        Dim komut As New OleDb.OleDbCommand(sql, baglanti)
        komut.Connection.Open()
        komut.ExecuteNonQuery()
        baglanti.Close()
    End Sub
End Module

 

Ekran Görüntüsü (veritabanı)

         

Konu 32: datasetten listbox'a tüm kayıtları çekme, datasetten listbox'a teker teker kayıt çekme, data reader yöntemi

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Dim baglanti As OleDb.OleDbConnection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        baglanti = New OleDb.OleDbConnection("Provider=Microsoft.Jet.oledb.4.0;data Source=" & Application.StartupPath & "\vt.mdb")

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sql As String = "select * from kisiler"
        Dim adaptor As New OleDb.OleDbDataAdapter(sql, baglanti)
        Dim ds As New DataSet
        adaptor.Fill(ds, "kisiler")
        baglanti.Close()

        ListBox1.DataSource = ds.Tables("kisiler")
        ListBox1.DisplayMember = "ad"

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim sql As String = "select * from kisiler"
        Dim adaptor As New OleDb.OleDbDataAdapter(sql, baglanti)
        Dim ds As New DataSet
        adaptor.Fill(ds, "kisiler")
        baglanti.Close()

        For i As Integer = 0 To ds.Tables("kisiler").Rows.Count - 1
            ListBox2.Items.Add(ds.Tables("kisiler").Rows(i).Item(2))
        Next
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim sql As String = "select * from kisiler"
        Dim komut As New OleDb.OleDbCommand(sql, baglanti)
        komut.Connection.Open()
        Dim okur As OleDb.OleDbDataReader
        okur = komut.ExecuteReader

        While okur.Read
            ListBox3.Items.Add(okur.GetString(3))
        End While
        baglanti.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim sql As String = "select * from il"
        Dim adaptor As New OleDb.OleDbDataAdapter(sql, baglanti)
        Dim ds As New DataSet
        adaptor.Fill(ds, "il")
        baglanti.Close()

        ComboBox1.DataSource = ds.Tables("il")
        ComboBox1.DisplayMember = "sehir"
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim sql As String = "select * from ilce where sehir=" & (ComboBox1.SelectedIndex + 1)
        Dim adaptor As New OleDb.OleDbDataAdapter(sql, baglanti)
        Dim ds As New DataSet
        adaptor.Fill(ds, "ilce")
        baglanti.Close()

        ComboBox2.DataSource = ds.Tables("ilce")
        ComboBox2.DisplayMember = "ilce"
    End Sub
End Class

Konu 31: datagridview görüntüleme ayarları, datagridview'dan veritabanına direkt kayıt

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Dim baglanti As OleDb.OleDbConnection
    Dim secilen As Integer
    Dim ds As DataSet

    Sub verigoster()
        Dim sql As String = "select * from kisiler"
        Dim adaptor As New OleDb.OleDbDataAdapter(sql, baglanti)
        ds = New DataSet
        adaptor.Fill(ds, "kisiler")
        baglanti.Close()
        DataGridView1.DataSource = ds.Tables("kisiler")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        baglanti = New OleDb.OleDbConnection("Provider=Microsoft.Jet.oledb.4.0;data Source=" & Application.StartupPath & "\vt.mdb")

        DataGridView1.AutoGenerateColumns = False
        DataGridView1.Columns.Add("sira", "SIRA")
        DataGridView1.Columns.Add("ad", "ADI")
        DataGridView1.Columns.Add("soyad", "SOYADI")
        DataGridView1.Columns.Add("tel", "TELEFON NUMARASI")
        DataGridView1.Columns.Add("para", "PARA DURUMU")
        DataGridView1.Columns("ad").Width = 75
        DataGridView1.Columns("soyad").Width = 75
        DataGridView1.Columns("tel").Width = 100
        DataGridView1.Columns("para").Width = 50

        DataGridView1.Columns("sira").DataPropertyName = "sira_no"
        DataGridView1.Columns("ad").DataPropertyName = "ad"
        DataGridView1.Columns("soyad").DataPropertyName = "soyad"
        DataGridView1.Columns("tel").DataPropertyName = "tel"
        DataGridView1.Columns("para").DataPropertyName = "para"

        DataGridView1.Columns("sira").Visible = False

        verigoster()
    End Sub

    Sub guncelle()
        Dim adaptor As New OleDb.OleDbDataAdapter("select * from kisiler", baglanti)
        Dim yapici As New OleDb.OleDbCommandBuilder(adaptor)
        adaptor.Update(ds.Tables("kisiler"))
        baglanti.Close()

        verigoster()
    End Sub

    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        secilen = DataGridView1.Rows(e.RowIndex).Cells(0).Value
        Label1.Text = secilen
    End Sub

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

End Class

Konu 30: Datasetteki Kayıtları Teker Teker Gezinme, Listboxta Datasource Ayarı Ve Veri Görüntüleme

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Dim baglanti As OleDb.OleDbConnection
    Sub verigoster()
        ListBox1.Items.Clear()
        ListBox2.Items.Clear()
        ListBox3.Items.Clear()
        Dim adaptor As New OleDb.OleDbDataAdapter("select * from rehber", baglanti)
        Dim veriseti As New DataSet
        adaptor.Fill(veriseti, "rehber")
        baglanti.Close()
        'datasetteki verileri teker teker gezmemizi saglar
        For i As Integer = 0 To veriseti.Tables("rehber").Rows.Count - 1
            Dim ad, soyad, tel As String
            ad = veriseti.Tables("rehber").Rows(i).Item(1)
            soyad = veriseti.Tables("rehber").Rows(i).Item(2)
            tel = veriseti.Tables("rehber").Rows(i).Item(3)
            ListBox1.Items.Add(ad)
            ListBox2.Items.Add(soyad)
            ListBox3.Items.Add(tel)
        Next
        'listboxın datasourceunu verisetinden cekmesini saglıyoruz
        ListBox4.DataSource = veriseti.Tables("rehber")
        'ListBox4.DisplayMember = "ad"
        'listbox verileri cekerken, verisetinin hangi sutunundan veriler alması gerektigini bildiriyoruz
        ListBox4.DisplayMember = veriseti.Tables("rehber").Columns(1).ColumnName
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        baglanti = New OleDb.OleDbConnection("Provider=Microsoft.Jet.oledb.4.0;Data source=" & Application.StartupPath & "\defter.mdb;")
        verigoster()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        verigoster()
    End Sub
End Class

Konu 29: veri tabanı örneği dataset mantığı, çoklu arama

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Dim baglanti As OleDb.OleDbConnection
    Dim secilen As Integer

    Sub verigoster()
        Dim adaptor As New OleDb.OleDbDataAdapter("select * from kisiler", baglanti)
        Dim ds As New DataSet
        adaptor.Fill(ds, "kisiler")
        DataGridView1.DataSource = ds.Tables("kisiler")
        baglanti.Close()
    End Sub

    Sub calistir(ByVal sql As String)
        Dim komut As New OleDb.OleDbCommand(sql, baglanti)
        komut.Connection.Open()
        komut.ExecuteNonQuery()
        baglanti.Close()
        verigoster()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        baglanti = New OleDb.OleDbConnection("Provider=Microsoft.Jet.oledb.4.0;Data Source=" & Application.StartupPath & "\vt.mdb")
        'MsgBox("Provider=Microsoft.Jet.oledb.4.0;Data Source=" & Application.StartupPath & "\vt1.mdb")
        verigoster()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim para As String = Replace(TextBox4.Text, ",", ".")
        If IsNumeric(para) = False Then
            MsgBox("para birimini hatalı girdiniz")
            Exi t Sub
        End If

        Dim sql As String = "insert into kisiler (ad,soyad,tel,para) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "'," & para & ")"
        calistir(sql)
    End Sub

    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        'MsgBox(e.RowIndex)
        secilen = DataGridView1.Rows(e.RowIndex).Cells(0).Value
        TextBox8.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
        TextBox7.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value
        TextBox6.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
        TextBox5.Text = DataGridView1.Rows(e.RowIndex).Cells(4).Value

        Label9.Text = secilen
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim para As String = Replace(TextBox5.Text, ",", ".")
        If IsNumeric(para) = False Then
            MsgBox("para birimini hatalı girdiniz")
            Exi t Sub
        End If
        Dim sql As String = "update kisiler set ad='" & TextBox8.Text & "',soyad='" & TextBox7.Text & "',tel='" & TextBox6.Text & "',para=" & para & " where sira_no=" & secilen
        calistir(sql)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim sql As String = "delete from kisiler where sira_no=" & secilen
        calistir(sql)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Dim sql As String = "select * from kisiler where ad like '%a%' and soyad like '%a%' and tel like '%1%' and para like 1 and"
        Dim sql As String = "select * from kisiler where "
        If CheckBox1.Checked Then
            sql &= "ad like '%" & TextBox12.Text & "%' and "
        End If
        If CheckBox2.Checked Then
            sql &= "soyad like '%" & TextBox11.Text & "%' and "
        End If
        If CheckBox3.Checked Then
            sql &= "tel like '%" & TextBox10.Text & "%' and "
        End If
        If CheckBox4.Checked Then
            sql &= "para like %" & TextBox9.Text & "% and "
        End If

        If sql.EndsWith("and ") Then
            'son 4 karakteri sil
            sql = sql.Remove(sql.Length - 4, 4)
        ElseIf sql.EndsWith("where ") Then
            'son 6 karakteri sil
            sql = sql.Remove(sql.Length - 6, 6)
        End If

        Dim adaptor As New OleDb.OleDbDataAdapter(sql, baglanti)
        Dim ds As New DataSet
        adaptor.Fill(ds, "kisiler")
        DataGridView1.DataSource = ds.Tables("kisiler")
        baglanti.Close()
    End Sub

    Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged, TextBox11.TextChanged, TextBox10.TextChanged, TextBox9.TextChanged
        'Dim sql As String = "select * from kisiler where ad like '%a%' and soyad like '%a%' and tel like '%1%' and para like 1 and"
        Dim sql As String = "select * from kisiler where "
        If CheckBox1.Checked Then
            sql &= "ad like '%" & TextBox12.Text & "%' and "
        End If
        If CheckBox2.Checked Then
            sql &= "soyad like '%" & TextBox11.Text & "%' and "
        End If
        If CheckBox3.Checked Then
            sql &= "tel like '%" & TextBox10.Text & "%' and "
        End If
        If CheckBox4.Checked Then
            sql &= "para like %" & TextBox9.Text & "% and "
        End If

        If sql.EndsWith("and ") Then
            'son 4 karakteri sil
            sql = sql.Remove(sql.Length - 4, 4)
        ElseIf sql.EndsWith("where ") Then
            'son 6 karakteri sil
            sql = sql.Remove(sql.Length - 6, 6)
        End If

        Dim adaptor As New OleDb.OleDbDataAdapter(sql, baglanti)
        Dim ds As New DataSet
        adaptor.Fill(ds, "kisiler")
        DataGridView1.DataSource = ds.Tables("kisiler")
        baglanti.Close()

    End Sub

End Class

Konu 28: Veritabanı Uygulaması Dataset Mantığı Veri gösterme, Delete Ve Select

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Dim Baglanti As OleDb.OleDbConnection
    Dim sira As Integer
    Sub verigoster()
        Dim Adaptor As New OleDb.OleDbDataAdapter("select * from rehber", Baglanti)
        Dim Ds As New DataSet
        Adaptor.Fill(Ds, "veri")
        DataGridView1.DataSource = Ds.Tables("veri")
        Baglanti.Close()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Baglanti = New OleDb.OleDbConnection("Provider=Microsoft.Jet.oledb.4.0;Data Source=" & Application.StartupPath & "\defter.mdb;")
        'MsgBox("Provider=Microsoft.Jet.4.0;Data Source=" & Application.StartupPath & "\defter.mdb;")
        verigoster()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sql As String = "insert into rehber (ad,soyad,tel) values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
        'MsgBox(sql)
        Dim Komut As New OleDb.OleDbCommand(sql, Baglanti)
        Komut.Connection.Open()
        Komut.ExecuteNonQuery()
        Baglanti.Close()
        verigoster()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim sql As String = "update rehber set ad='" & TextBox4.Text & "', soyad='" & TextBox5.Text & "', tel='" & TextBox6.Text & "' where sira_no=" & sira
        Dim Komut As New OleDb.OleDbCommand(sql, Baglanti)
        Komut.Connection.Open()
        Komut.ExecuteNonQuery()
        Baglanti.Close()
        verigoster()
    End Sub
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        sira = DataGridView1.Rows(e.RowIndex).Cells(0).Value
        Label10.Text = sira
        Label7.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
        Label8.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value
        Label9.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim hangisi As String = ""
        If RadioButton1.Checked Then
            hangisi = "ad"
        ElseIf RadioButton2.Checked Then
            hangisi = "soyad"
        ElseIf RadioButton3.Checked Then
            hangisi = "tel"
        End If
        Dim sql As String = "delete from rehber where " & hangisi & "='" & TextBox7.Text & "'"
        Dim Komut As New OleDb.OleDbCommand(sql, Baglanti)
        Komut.Connection.Open()
        Komut.ExecuteNonQuery()
        Baglanti.Close()
        verigoster()
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim hangisi As String = ""
        If RadioButton4.Checked Then
            hangisi = "ad"
        ElseIf RadioButton5.Checked Then
            hangisi = "soyad"
        ElseIf RadioButton6.Checked Then
            hangisi = "tel"
        End If
        Dim sql As String
        If TextBox8.Text = "" Then
            sql = "select * from rehber"
        Else
            sql = "select * from rehber where " & hangisi & "='" & TextBox8.Text & "'"
        End If

        Dim Adaptor As New OleDb.OleDbDataAdapter(Sql, Baglanti)
        Dim Ds As New DataSet
        Adaptor.Fill(Ds, "veri")
        DataGridView1.DataSource = Ds.Tables("veri")
        Baglanti.Close()
    End Sub
End Class

Konu 27: Veritabanı Uygulaması Dataset Mantığı Veri gösterme, İnsert Ve Update

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Dim Baglanti As OleDb.OleDbConnection
    Dim sira As Integer
    Sub verigoster()
        Dim Adaptor As New OleDb.OleDbDataAdapter("select * from rehber", Baglanti)
        Dim Ds As New DataSet
        Adaptor.Fill(Ds, "veri")
        DataGridView1.DataSource = Ds.Tables("veri")
        Baglanti.Close()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Baglanti = New OleDb.OleDbConnection("Provider=Microsoft.Jet.oledb.4.0;Data Source=" & Application.StartupPath & "\defter.mdb;")
        'MsgBox("Provider=Microsoft.Jet.4.0;Data Source=" & Application.StartupPath & "\defter.mdb;")
        verigoster()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sql As String = "insert into rehber (ad,soyad,tel) values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
        'MsgBox(sql)
        Dim Komut As New OleDb.OleDbCommand(sql, Baglanti)
        Komut.Connection.Open()
        Komut.ExecuteNonQuery()
        Baglanti.Close()
        verigoster()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim sql As String = "update rehber set ad='" & TextBox4.Text & "', soyad='" & TextBox5.Text & "', tel='" & TextBox6.Text & "' where sira_no=" & sira
        Dim Komut As New OleDb.OleDbCommand(sql, Baglanti)
        Komut.Connection.Open()
        Komut.ExecuteNonQuery()
        Baglanti.Close()
        verigoster()
    End Sub

    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        sira = DataGridView1.Rows(e.RowIndex).Cells(0).Value
        Label10.Text = sira
        Label7.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
        Label8.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value
        Label9.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
    End Sub
End Class

Konu 26: Modül Kullanımı, Context Menü Kullanımı

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        adi = TextBox1.Text
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form2.Show()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Label1.Text = topla(Val(TextBox2.Text), Val(TextBox3.Text))
    End Sub
    Private Sub KesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KesToolStripMenuItem.Click
        Dim kontrol As TextBox = ContextMenuStrip1.SourceControl
        kontrol.Cut()
    End Sub

    Private Sub HepsiniSeçToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HepsiniSeçToolStripMenuItem.Click
        'MsgBox(ContextMenuStrip1.SourceControl.Text)
        Dim kontrol As TextBox = ContextMenuStrip1.SourceControl
        kontrol.SelectAll()
    End Sub

    Private Sub KopyalaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KopyalaToolStripMenuItem.Click
        Dim kontrol As TextBox = ContextMenuStrip1.SourceControl
        kontrol.Copy()
    End Sub

    Private Sub YapıştırToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YapıştırToolStripMenuItem.Click
        Dim kontrol As TextBox = ContextMenuStrip1.SourceControl
        kontrol.Paste()
    End Sub
End Class

Ekran Görüntüsü 2

Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = adi
    End Sub
End Class

 

Module Module1
    Public adi As String

    Public Function topla(ByVal a As Integer, ByVal b As Integer) As Integer
        topla = a + b
    End Function

    Sub main()
        'MsgBox("selam")
        Dim kullanici As String = InputBox("kullanıcı adını giriniz", "kullanıcı girişi", "admin")
        Dim sifre As String = InputBox("sifrenizi giriniz", "sifre girisi")
        If kullanici = "admin" And sifre = "1" Then
            Form1.ShowDialog()
        Else
            MsgBox("hatalı bilgi girisi. form kapatılacak")
        End If

    End Sub
End Module

Konu 25: Class Yapısı, Listboxla Kullanımı, Tostring Fonksiyonu, New Yordamı

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Public Class musteri
        Public isim As String
        Public tel, adres As String
        Public baslangic, bitis As Date

        Public Overrides Function ToString() As String
            Return isim & "--" & tel
        End Function

        Public Sub New(ByVal isim As String, ByVal telefon As String, ByVal adres As String, ByVal baslangic_tarihi As Date, ByVal bitis_tarihi As Date)
            Me.isim = isim
            Me.tel = telefon
            Me.adres = adres
            Me.baslangic = baslangic_tarihi
            Me.bitis = bitis_tarihi
        End Sub

    End Class

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'degisken olusturulur
        Dim kayit As New musteri(TextBox1.Text, TextBox2.Text, TextBox3.Text, DateTimePicker1.Value, DateTimePicker2.Value)

        ListBox1.Items.Add(kayit)
        'kullanıcıdan alınan bilgiler labellarda gosterilir
        Label6.Text = kayit.isim
        Label7.Text = kayit.tel
        Label8.Text = kayit.adres
        MonthCalendar1.SelectionStart = kayit.baslangic
        MonthCalendar1.SelectionEnd = kayit.bitis
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim secilen As musteri
        secilen = ListBox1.SelectedItem
        Label6.Text = secilen.isim
        Label7.Text = secilen.tel
        Label8.Text = secilen.adres
        MonthCalendar1.SelectionStart = secilen.baslangic
        MonthCalendar1.SelectionEnd = secilen.bitis
    End Sub

End Class

Konu 24: Class Yapısı Ve Dizilerle Kullanımı

Örnek Uygulama

Ekran Görüntüsü

Public Class Form1
    Public Class musteri
        Public isim As String
        Public tel, adres As String
        Public baslangic, bitis As Date
    End Class
    Dim kayitlar() As musteri
    Dim sayi As Integer = -1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'degisken olusturulur
        Dim kayit As New musteri
        'bilgiler formdan alınır
        kayit.isim = TextBox1.Text
        kayit.tel = TextBox2.Text
        kayit.adres = TextBox3.Text
        kayit.baslangic = DateTimePicker1.Value
        kayit.bitis = DateTimePicker2.Value

        sayi = sayi + 1
        ReDim Preserve kayitlar(sayi)
        kayitlar(sayi) = kayit
        'kullanıcıdan alınan bilgiler labellarda gosterilir
        Label6.Text = kayit.isim
        Label7.Text = kayit.tel
        Label8.Text = kayit.adres
        Label9.Text = kayit.baslangic
        Label10.Text = kayit.bitis
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        For i As Integer = 0 To UBound(kayitlar)
            ListBox1.Items.Add(kayitlar(i).isim & "--" & kayitlar(i).tel)
        Next
    End Sub
End Class