Skip to main content

AccessTr.neT


VB 2010 Kayıt Hatası

VB 2010 Kayıt Hatası

#1
Arkadaşlar merhaba,

Yapmış olduğum projede bazı hatalar alıyorum;
Kayıt, değiştirme ve aramada hatalar ile karşılaşıyorum yardımlarınızı bekliyorum.

Teşekkürler
İyi günler.
Kod:
Imports System.Data.OleDb
Public Class Form1
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       DataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically
       DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
       Listele("SELECT * FROM boto'")
       doldur()

       Label14.Text = TimeOfDay
       Timer1.Interval = 100
       Timer1.Enabled = True
   End Sub
   'DataGridView nesnesine verileri aktar
   Private Sub Listele(ByVal SQL As String)
       Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'") 'Veritabanımızın Türünü ve nerede olduğu
       Dim veriler As New DataTable("boto")
       Dim adapter As New OleDbDataAdapter(SQL, baglanti)
       adapter.Fill(veriler) 'VB.NET içersinde oluşturduğumuz sanal tablo.(veriler)Sanal tablonun ismi.
       DataGridView1.DataSource = veriler 'veri tabanından gelen verileri DataGridView nesnemize aktarıyoruz .

   End Sub
   Private Sub doldur()
       Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
       baglanti.Open()
       Dim komut As New OleDb.OleDbCommand("SELECT ID FROM boto ORDER BY ID", baglanti)
       Dim oku As OleDb.OleDbDataReader
       oku = komut.ExecuteReader()
       While oku.Read()
           ComboBox3.Items.Add(oku("ID"))
       End While
       baglanti.Close()
   End Sub


   'formumuzun üzerindeki nesneleri temizle
   Private Sub Temizle()
       TextBox1.Clear()
       TextBox2.Clear()
       TextBox4.Clear()
       TextBox5.Clear()
       TextBox6.Clear()
       TextBox7.Clear()
       TextBox8.Clear()
   End Sub
   'KAYDET
   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       If Me.TextBox2.Text = "" Then
           MsgBox("Lütfen aracın plakasını yazınız.", MsgBoxStyle.Exclamation, "Kayıt Uyarı")
       Else

           Dim sql As New String("INSERT INTO boto (ID,Birim,Tarih,Plaka,Tip,Şase,Danışman,Kontrol-no,Gbirim,Gtarih,Gdanışman,Gnot) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')")
           sql = String.Format(sql, TextBox1.Text, ComboBox1.Text, DateTimePicker1.Text, TextBox2.Text, ComboBox4.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, ComboBox2.Text, DateTimePicker2.Text, TextBox7.Text, TextBox8.Text)
           Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
           Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
           Dim sonuc As Integer
           baglanti.Open()
           sonuc = komutnesnesi.ExecuteNonQuery()
           If sonuc = 1 Then
               MsgBox("Fatura bilgileri kayıt edilmiştir.", MsgBoxStyle.Exclamation, "Tebrikler")
           End If
           Listele("SELECT * FROM boto'")
           baglanti.Close()
           Temizle()

       End If

       Me.ComboBox3.Text = ""
   End Sub
   'DEĞİŞİKLİKLERİ KAYDET.
   'Burada DataGrid içerisinden seçtiğimiz kaydı düzenleyerek kaydetmemize yarayan kodlar vardır.
   Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       If Me.TextBox1.Text = "" Then
           MsgBox("Lütfen kayıt seçiniz.", MsgBoxStyle.Exclamation, "DİKKAT")
       Else
           Dim sql As New String("UPDATE Kayitlar SET ID='{0}',Birim='{1}',Tarih='{2}',Plaka='{3}',Tip='{4}',Şase='{5}',Danışman='{6}',Kontrol-no='{7}',Danışman='{8}',Gtarih='{9}',Gdanışman='{10}' WHERE Gnot='{11}' ")
           sql = String.Format(sql, TextBox1.Text, ComboBox1.Text, DateTimePicker1.Text, TextBox2.Text, ComboBox4.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, ComboBox2.Text, DateTimePicker2.Text, TextBox7.Text, TextBox8.Text, DataGridView1.CurrentRow.Cells(0).Value)
           Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
           Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
           Dim sonuc As Integer
           baglanti.Open()
           sonuc = komutnesnesi.ExecuteNonQuery()
           If sonuc = 1 Then
               MsgBox("Fatura bilgileri güncellenmiştir.", MsgBoxStyle.Exclamation, "Değişiklik Uyarısı")
           End If
           Listele("SELECT * FROM boto'")
           baglanti.Close()
           Temizle()
       End If
       Me.ComboBox3.Text = ""
   End Sub
   'Sil Butonu
   'DataGrid üzerinden seçilen kaydı silmemize yarar.
   Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
       If Me.TextBox1.Text = "" Then
           MsgBox("Lütfen silmek istediğiniz faturayı seçiniz.", MsgBoxStyle.Exclamation, "DİKKAT")
       Else
           Dim sql As New String("DELETE FROM boto WHERE ID={0}")
           sql = String.Format(sql, DataGridView1.CurrentRow.Cells(0).Value)
           Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
           Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
           Dim sonuc As Integer
           baglanti.Open()
           sonuc = komutnesnesi.ExecuteNonQuery()
           If sonuc = 1 Then
               MsgBox("Seçmiş olduğunuz fatura silinmiştir.", MsgBoxStyle.Exclamation, "Silme İşlemi")

           End If
           Listele("SELECT * FROM Kayitlar'")
           baglanti.Close()
           Temizle()
       End If
   End Sub
   'DataGrid tıklandığında ilgili kaydın Metin Kutularına aktarılması.

   Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
       TextBox1.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(0).Value), "", DataGridView1.CurrentRow.Cells(0).Value) 'İlgili alan boş ise TextBox'a boş olarak ataması.
       ComboBox1.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(1).Value), "", DataGridView1.CurrentRow.Cells(1).Value)
       DateTimePicker1.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(2).Value), "", DataGridView1.CurrentRow.Cells(2).Value)
       TextBox2.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(3).Value), "", DataGridView1.CurrentRow.Cells(3).Value)
       ComboBox4.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(4).Value), "", DataGridView1.CurrentRow.Cells(4).Value)
       TextBox4.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(5).Value), "", DataGridView1.CurrentRow.Cells(5).Value)
       TextBox5.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(6).Value), "", DataGridView1.CurrentRow.Cells(6).Value)
       TextBox6.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(7).Value), "", DataGridView1.CurrentRow.Cells(7).Value)
       ComboBox2.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(8).Value), "", DataGridView1.CurrentRow.Cells(8).Value)
       DateTimePicker2.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(9).Value), "", DataGridView1.CurrentRow.Cells(9).Value)
       TextBox7.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(10).Value), "", DataGridView1.CurrentRow.Cells(10).Value)
       TextBox8.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(11).Value), "", DataGridView1.CurrentRow.Cells(11).Value)
   End Sub


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



   Private Sub ComboBox3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox3.TextChanged
       If Me.ComboBox3.Text > "" Then

           Dim sql As New String("SELECT * FROM boto WHERE boto.Kontrol-no='{7}'")
           sql = String.Format(sql, ComboBox3.SelectedItem)
           Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
           Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
           Dim sonuc As Integer
           baglanti.Open()
           sonuc = komutnesnesi.ExecuteNonQuery()
           If sonuc = 1 Then
               MsgBox("Hatayı Kontrol Ediniz.", MsgBoxStyle.Exclamation, "Silme İşlemi")

           End If
           Listele(sql)
           baglanti.Close()
       Else
           Dim sql As New String("SELECT * FROM boto '")
           sql = String.Format(sql, ComboBox3.SelectedItem)
           Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
           Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
           Dim sonuc As Integer
           baglanti.Open()
           sonuc = komutnesnesi.ExecuteNonQuery()
           If sonuc = 1 Then
               MsgBox("Hatayı Kontrol Ediniz.", MsgBoxStyle.Exclamation, "Silme İşlemi")

           End If
           Listele(sql)
           baglanti.Close()
       End If
   End Sub




   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
       Label14.Text = TimeOfDay
   End Sub

   Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
       Me.ComboBox3.Text = ""
   End Sub
End Class

.zip takip.zip (Dosya Boyutu: 125,83 KB | İndirme Sayısı: 10)
Cevapla
#2
(11/09/2015, 11:15)cix06 yazdı: Arkadaşlar merhaba,

Yapmış olduğum projede bazı hatalar alıyorum;
Kayıt, değiştirme ve aramada hatalar ile karşılaşıyorum yardımlarınızı bekliyorum.

Teşekkürler
İyi günler.
Kod:
Imports System.Data.OleDb
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically
        DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        Listele("SELECT * FROM boto'")
        doldur()

        Label14.Text = TimeOfDay
        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub
    'DataGridView nesnesine verileri aktar
    Private Sub Listele(ByVal SQL As String)
        Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'") 'Veritabanımızın Türünü ve nerede olduğu
        Dim veriler As New DataTable("boto")
        Dim adapter As New OleDbDataAdapter(SQL, baglanti)
        adapter.Fill(veriler) 'VB.NET içersinde oluşturduğumuz sanal tablo.(veriler)Sanal tablonun ismi.
        DataGridView1.DataSource = veriler 'veri tabanından gelen verileri DataGridView nesnemize aktarıyoruz .

    End Sub
    Private Sub doldur()
        Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
        baglanti.Open()
        Dim komut As New OleDb.OleDbCommand("SELECT ID FROM boto ORDER BY ID", baglanti)
        Dim oku As OleDb.OleDbDataReader
        oku = komut.ExecuteReader()
        While oku.Read()
            ComboBox3.Items.Add(oku("ID"))
        End While
        baglanti.Close()
    End Sub


    'formumuzun üzerindeki nesneleri temizle
    Private Sub Temizle()
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox4.Clear()
        TextBox5.Clear()
        TextBox6.Clear()
        TextBox7.Clear()
        TextBox8.Clear()
    End Sub
    'KAYDET
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Me.TextBox2.Text = "" Then
            MsgBox("Lütfen aracın plakasını yazınız.", MsgBoxStyle.Exclamation, "Kayıt Uyarı")
        Else

            Dim sql As New String("INSERT INTO boto (ID,Birim,Tarih,Plaka,Tip,Şase,Danışman,Kontrol-no,Gbirim,Gtarih,Gdanışman,Gnot) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')")
            sql = String.Format(sql, TextBox1.Text, ComboBox1.Text, DateTimePicker1.Text, TextBox2.Text, ComboBox4.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, ComboBox2.Text, DateTimePicker2.Text, TextBox7.Text, TextBox8.Text)
            Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
            Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
            Dim sonuc As Integer
            baglanti.Open()
            sonuc = komutnesnesi.ExecuteNonQuery()
            If sonuc = 1 Then
                MsgBox("Fatura bilgileri kayıt edilmiştir.", MsgBoxStyle.Exclamation, "Tebrikler")
            End If
            Listele("SELECT * FROM boto'")
            baglanti.Close()
            Temizle()

        End If

        Me.ComboBox3.Text = ""
    End Sub
    'DEĞİŞİKLİKLERİ KAYDET.
    'Burada DataGrid içerisinden seçtiğimiz kaydı düzenleyerek kaydetmemize yarayan kodlar vardır.
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Me.TextBox1.Text = "" Then
            MsgBox("Lütfen kayıt seçiniz.", MsgBoxStyle.Exclamation, "DİKKAT")
        Else
            Dim sql As New String("UPDATE Kayitlar SET ID='{0}',Birim='{1}',Tarih='{2}',Plaka='{3}',Tip='{4}',Şase='{5}',Danışman='{6}',Kontrol-no='{7}',Danışman='{8}',Gtarih='{9}',Gdanışman='{10}' WHERE Gnot='{11}' ")
            sql = String.Format(sql, TextBox1.Text, ComboBox1.Text, DateTimePicker1.Text, TextBox2.Text, ComboBox4.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, ComboBox2.Text, DateTimePicker2.Text, TextBox7.Text, TextBox8.Text, DataGridView1.CurrentRow.Cells(0).Value)
            Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
            Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
            Dim sonuc As Integer
            baglanti.Open()
            sonuc = komutnesnesi.ExecuteNonQuery()
            If sonuc = 1 Then
                MsgBox("Fatura bilgileri güncellenmiştir.", MsgBoxStyle.Exclamation, "Değişiklik Uyarısı")
            End If
            Listele("SELECT * FROM boto'")
            baglanti.Close()
            Temizle()
        End If
        Me.ComboBox3.Text = ""
    End Sub
    'Sil Butonu
    'DataGrid üzerinden seçilen kaydı silmemize yarar.
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Me.TextBox1.Text = "" Then
            MsgBox("Lütfen silmek istediğiniz faturayı seçiniz.", MsgBoxStyle.Exclamation, "DİKKAT")
        Else
            Dim sql As New String("DELETE FROM boto WHERE ID={0}")
            sql = String.Format(sql, DataGridView1.CurrentRow.Cells(0).Value)
            Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
            Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
            Dim sonuc As Integer
            baglanti.Open()
            sonuc = komutnesnesi.ExecuteNonQuery()
            If sonuc = 1 Then
                MsgBox("Seçmiş olduğunuz fatura silinmiştir.", MsgBoxStyle.Exclamation, "Silme İşlemi")

            End If
            Listele("SELECT * FROM Kayitlar'")
            baglanti.Close()
            Temizle()
        End If
    End Sub
    'DataGrid tıklandığında ilgili kaydın Metin Kutularına aktarılması.

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        TextBox1.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(0).Value), "", DataGridView1.CurrentRow.Cells(0).Value) 'İlgili alan boş ise TextBox'a boş olarak ataması.
        ComboBox1.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(1).Value), "", DataGridView1.CurrentRow.Cells(1).Value)
        DateTimePicker1.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(2).Value), "", DataGridView1.CurrentRow.Cells(2).Value)
        TextBox2.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(3).Value), "", DataGridView1.CurrentRow.Cells(3).Value)
        ComboBox4.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(4).Value), "", DataGridView1.CurrentRow.Cells(4).Value)
        TextBox4.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(5).Value), "", DataGridView1.CurrentRow.Cells(5).Value)
        TextBox5.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(6).Value), "", DataGridView1.CurrentRow.Cells(6).Value)
        TextBox6.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(7).Value), "", DataGridView1.CurrentRow.Cells(7).Value)
        ComboBox2.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(8).Value), "", DataGridView1.CurrentRow.Cells(8).Value)
        DateTimePicker2.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(9).Value), "", DataGridView1.CurrentRow.Cells(9).Value)
        TextBox7.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(10).Value), "", DataGridView1.CurrentRow.Cells(10).Value)
        TextBox8.Text = IIf(IsDBNull(DataGridView1.CurrentRow.Cells(11).Value), "", DataGridView1.CurrentRow.Cells(11).Value)
    End Sub


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



    Private Sub ComboBox3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox3.TextChanged
        If Me.ComboBox3.Text > "" Then

            Dim sql As New String("SELECT * FROM boto WHERE boto.Kontrol-no='{7}'")
            sql = String.Format(sql, ComboBox3.SelectedItem)
            Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
            Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
            Dim sonuc As Integer
            baglanti.Open()
            sonuc = komutnesnesi.ExecuteNonQuery()
            If sonuc = 1 Then
                MsgBox("Hatayı Kontrol Ediniz.", MsgBoxStyle.Exclamation, "Silme İşlemi")

            End If
            Listele(sql)
            baglanti.Close()
        Else
            Dim sql As New String("SELECT * FROM boto '")
            sql = String.Format(sql, ComboBox3.SelectedItem)
            Dim baglanti As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='bdata.mdb'")
            Dim komutnesnesi As New OleDb.OleDbCommand(sql, baglanti)
            Dim sonuc As Integer
            baglanti.Open()
            sonuc = komutnesnesi.ExecuteNonQuery()
            If sonuc = 1 Then
                MsgBox("Hatayı Kontrol Ediniz.", MsgBoxStyle.Exclamation, "Silme İşlemi")

            End If
            Listele(sql)
            baglanti.Close()
        End If
    End Sub




    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label14.Text = TimeOfDay
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Me.ComboBox3.Text = ""
    End Sub
End Class


Örnek veriyorum

Veritabanındaki ID alanın sayısal türde ise
'{0}' değil {0}
eğer sayısal değilde metinse '{0}' bu şekilde olacak

String cümleni kontrol et

Dim Sql As New String("INSERT INTO boto (ID,Birim) values ('{0}','{1}')")
drummers, 11-05-2009 tarihinden beri AccessTr.neT üyesidir.
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da
Task