Forum

VB.Net Veritabanına...
 
Bildirimler
Hepsini Temizle

VB.Net Veritabanına bir kaydı üç kez kayıt ediyor yardımm...

2 Yazılar
2 Üyeler
0 Reactions
753 Görüntüleme
(@serhatisbilir)
Gönderiler: 67
Estimable Member
Konu başlatıcı
 

Personel Takip Programı yapıyorum arkadaşlar... bir kayıt ekliyorum fakat aynı kaydı 3 kez veri tabanına işliyor....

 

kodlarım...

 

 

Imports System.Data.OleDb

Public Class Form1

    Public bag As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=data.mdb")

    Public kmt As New OleDbCommand()

    Public adtr As New OleDbDataAdapter()

    Public dtst As New DataSet()

    Public Sub combo()

        bag.Open()

        kmt.Connection = bag

        kmt.CommandText = "Select * from bölüm"

        Dim oku As OleDbDataReader

        oku = kmt.ExecuteReader()

        While oku.Read()

            comboBox1.Items.Add(oku(0).ToString())

        End While

        bag.Close()

        oku.Dispose()

        comboBox1.Sorted = True

    End Sub

    Public Sub combo2()

        bag.Open()

        kmt.Connection = bag

        kmt.CommandText = "Select * from bölüm"

        Dim oku As OleDbDataReader

        oku = kmt.ExecuteReader()

        While oku.Read()

            Form3.comboBox1.Items.Add(oku(0).ToString())

        End While

        bag.Close()

        oku.Dispose()

        Form3.comboBox1.Sorted = True

    End Sub

    Public Sub listelesene()

        bag.Open()

        Dim adtr As New OleDbDataAdapter("select * From kayit", bag)

        adtr.Fill(dtst, "kayit")

        Form3.dataView1.Table = dtst.Tables(0)

        Form3.dataGrid1.DataSource = Form3.dataView1

        adtr.Dispose()

        bag.Close()

    End Sub

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

        combo()

    End Sub

  

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        Form3.Show()

        Me.Hide()

    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click

        If textBox1.Text <> "" AndAlso textBox2.Text <> "" AndAlso comboBox1.Text <> "" Then

            bag.Open()

            kmt.Connection = bag

            kmt.CommandText = "insert into kayit values ('" & textBox1.Text & "','" & textBox2.Text & "','" & textBox3.Text & "','" & textBox4.Text & "','" & textBox5.Text & "','" & ComboBox1.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "')"

            kmt.ExecuteNonQuery()

            kmt.ExecuteNonQuery()

            kmt.ExecuteNonQuery()

            kmt.Dispose()

            bag.Close()

            comboBox1.Items.Clear()

            textBox1.Clear()

            textBox2.Clear()

            textBox3.Clear()

            textBox4.Clear()

            textBox5.Clear()

            textBox6.Clear()

            textBox7.Clear()

            textBox8.Clear()

            textBox9.Clear()

            comboBox1.Text = ""

            combo()

            MessageBox.Show("Kayıt işlemi tamamlandı ! ")

        Else

            MessageBox.Show("Boş alanları doldurunuz !!!")

        End If

    End Sub

    Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button4.Click

        Me.Close()

    End Sub

  

End Class

 

Public Class Form3

    Private Sub texteyaz()

        textBox14.Text = (Me.BindingContext(Form1.dtst, "kayit").Position + 1) & " / " & Me.BindingContext(Form1.dtst, "kayit").Count

    End Sub

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

        Form1.combo2()

        Form1.listelesene()

        textBox1.DataBindings.Add("Text", Form1.dtst, "kayit.Adi")

        textBox2.DataBindings.Add("Text", Form1.dtst, "kayit.Soyadi")

        textBox3.DataBindings.Add("Text", Form1.dtst, "kayit.İp_Adres")

        textBox4.DataBindings.Add("Text", Form1.dtst, "kayit.Tel_No")

        textBox5.DataBindings.Add("Text", Form1.dtst, "kayit.E_Posta")

        TextBox6.DataBindings.Add("Text", Form1.dtst, "kayit.User_name")

        TextBox7.DataBindings.Add("Text", Form1.dtst, "kayit.Password")

        TextBox8.DataBindings.Add("Text", Form1.dtst, "kayit.DB_Login_name")

        TextBox9.DataBindings.Add("Text", Form1.dtst, "kayit.DB_Login_password")

        ComboBox1.DataBindings.Add("Text", Form1.dtst, "kayit.bölüm")

        texteyaz()

        textBox1.Enabled = False

        textBox2.Enabled = False

        textBox3.Enabled = False

        textBox4.Enabled = False

        textBox5.Enabled = False

        TextBox6.Enabled = False

        TextBox7.Enabled = False

        TextBox8.Enabled = False

        TextBox9.Enabled = False

        ComboBox1.Enabled = False

      

    End Sub

    Private Sub button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button6.Click

        Form1.Show()

        Me.Hide()

    End Sub

    Private Sub button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button5.Click

        If textBox1.Text <> "" AndAlso textBox2.Text <> "" AndAlso comboBox1.Text <> "" Then

            Dim cevap As DialogResult

            cevap = MessageBox.Show("Kaydı silmek istediğinizden eminmisiniz", "Uyarı", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If cevap = DialogResult.Yes Then

                Form1.bag.Open()

                Form1.kmt.Connection = Form1.bag

                Form1.kmt.CommandText = "DELETE from kayit WHERE Adi='" + textBox1.Text & "'"

                Form1.kmt.CommandType = CommandType.Text

                Form1.kmt.ExecuteNonQuery()

                Form1.kmt.ExecuteNonQuery()

                Form1.kmt.ExecuteNonQuery()

                Form1.kmt.Dispose()

                Form1.bag.Close()

                comboBox1.Items.Clear()

                Form1.comboBox1.Items.Clear()

                comboBox1.Text = ""

                Form1.combo()

                Form1.combo2()

                Form1.dtst.Clear()

                Form1.listelesene()

            End If

        Else

            MessageBox.Show("Boş alanları doldurunuz !!!")

        End If

    End Sub

    Private Sub button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button7.Click

        Application.Exit()

    End Sub

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        Me.BindingContext(Form1.dtst, "kayit").Position = 0

        texteyaz()

    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click

        Me.BindingContext(Form1.dtst, "kayit").Position -= 1

        texteyaz()

    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click

        Me.BindingContext(Form1.dtst, "kayit").Position += 1

        texteyaz()

    End Sub

    Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button4.Click

        Me.BindingContext(Form1.dtst, "kayit").Position = Me.BindingContext(Form1.dtst, "kayit").Count

        texteyaz()

    End Sub

    Private Sub textBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textBox1.TextChanged

    End Sub

End Class 

 

 

 

 
Gönderildi : 28/03/2012 18:14

(@ErcanAyhan)
Gönderiler: 54
Trusted Member
 

kmt.executenonqery(); bunu 3 defa yazmışsın 🙂 1 defa yazarsan sorun kalkar..

 
Gönderildi : 29/03/2012 02:24

Paylaş: