-2
Imports System.Data
Imports System.Data.OleDb
Public Class Form_Input_Data_Kelahiran
    Dim jenis As String
    Dim rd As OleDbDataReader
    Dim nik As Integer
    Dim perintah As New OleDbCommand() 'buat koneksi simpan/insert'
    Dim isi As String
    Sub filtabel()
        Call bukakoneksi()
        Dim dt As New DataTable
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String

        sql = "SELECT * FROM tblkelahiran ORDER BY no_kk asc"


        da = New OleDb.OleDbDataAdapter(sql, konekOLEDB)
        da.Fill(dt)

        konekOLEDB.Close()
        txtnokk.Focus()
    End Sub
    Sub add()
        Call bukakoneksi()

        Try

            Dim perintah As New OleDbCommand()
            Dim isi As String

            isi = " Insert into tblkelahiran (no_kk,nm_kk,nm_lgkp,jenis_klmn,tmpt_dilahirkan,tmpt_kelahiran,tgl_lhr,umur,jenis_kelahiran,penolong,berat,panjang,nik_ibu,nm_ibu,tgl_ibu,pekerjaan_ibu,alamat_ibu,kewarganegaraan_ibu,kebangsaan_ibu,tgl_pencatatan,nik_ayah,nm_ayah,tgl_ayah,pekerjaan_ayah,alamat_ayah,kewarganegaraan_ayah,kebangsaan_ayah,nik_pelapor,nm_pelapor,hubungan,nik_saksi1,nm_saksi1,nik_saksi2,nm_saksi2) values ('" & txtnokk.Text & "','" & txtnamakeluarga.Text & "','" & txtnama1.Text & "','" & cmbkelamin1.Text & "','" & cmbdilahirkan1.Text & "','" & cmbkelahiran1.Text & "','" & dtplahir1.Text & "','" & txtumur1.Text & "','" & cmbjenis.Text & "','" & txtpenolong1.Text & "','" & txtberat.Text & "','" & txtpanjang.Text & "','" & txtnik2.Text & "','" & txtnama2.Text & "','" & cmbpekerjaan2.Text & "','" & dtplahir2.Text & "','" & txtalamat2.Text & "','" & cmbnegara2.Text & "', '" & cmbbangsa2.Text & "','" & dtppekawinan.Text & "','" & txtnik3.Text & "','" & txtnama3.Text & "', '" & cmbpekerjaan3.Text & "','" & dtplahir3.Text & "','" & txtalamat3.Text & "','" & cmbnegara3.Text & "','" & cmbbangsa3.Text & "','" & txtnik4.Text & "','" & txtnama4.Text & "','" & txthubungan.Text & "','" & txtnik5.Text & "','" & txtnama5.Text & "','" & txtnik6.Text & "','" & txtnama6.Text & "' )"

            perintah = New OleDbCommand(isi, konekOLEDB)
            perintah.ExecuteNonQuery()

            konekOLEDB.Close()
            MsgBox("Data berhasil Dimasukkan")


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Sub bindingdata(ByVal nis As Integer)

        Dim dbread As OleDbDataReader
        Dim perintah As New OleDbCommand

        bukakoneksi()

        perintah = New OleDbCommand("SELECT * FROM tblkelahiran where no_kk = @no_kk", konekOLEDB)
        perintah.Parameters.AddWithValue("@no_kk", nik)
        dbread = perintah.ExecuteReader
        If dbread.Read() Then
            txtnokk.Text = dbread("no_kk").ToString
            txtnamakeluarga.Text = dbread("nm_kk").ToString
            txtnama1.Text = dbread("nm_lgkp").ToString
            cmbkelamin1.Text = dbread("jenis_klmn").ToString
            cmbdilahirkan1.Text = dbread("tmpt_dilahirkan").ToString
            cmbkelahiran1.Text = dbread("tmpt_kelahiran").ToString
            dtplahir1.Text = dbread("tgl_lhr").ToString
            txtumur1.Text = dbread("umur").ToString
            cmbjenis.Text = dbread("jenis_kelahiran").ToString
            txtpenolong1.Text = dbread("penolong").ToString
            txtberat.Text = dbread("berat").ToString
            txtpanjang.Text = dbread("panjang").ToString
            txtnik2.Text = dbread("nik_ibu").ToString
            txtnama2.Text = dbread("nm_ibu").ToString
            dtplahir2.Text = dbread("tgl_ibu").ToString
            cmbpekerjaan2.Text = dbread("pekerjaan_ibu").ToString
            txtalamat2.Text = dbread("alamat_ibu").ToString
            cmbnegara2.Text = dbread("kewarganegaraan_ibu").ToString
            cmbbangsa2.Text = dbread("kebangsaan_ibu").ToString
            dtppekawinan.Text = dbread("tgl_pencatatan").ToString
            txtnik3.Text = dbread("nik_ayah").ToString
            txtnama3.Text = dbread("nm_ayah").ToString
            dtplahir3.Text = dbread("tgl_ayah").ToString
            cmbpekerjaan3.Text = dbread("pekerjaan_ayah").ToString
            cmbnegara3.Text = dbread("kewarganegaraan_ayah").ToString
            cmbbangsa3.Text = dbread("kebangsaan_ayah").ToString
            txtnik4.Text = dbread("nik_pelapor").ToString
            txtnama4.Text = dbread("nm_pelapor").ToString
            txthubungan.Text = dbread("hubungan").ToString
            txtnik5.Text = dbread("nik_saksi1").ToString
            txtnama5.Text = dbread("nm_saksi1").ToString
            txtnik6.Text = dbread("nik_saksi2").ToString
            txtnama6.Text = dbread("nm_saksi2").ToString

        End If
        konekOLEDB.Close()
    End Sub
    Function validasi() As Boolean
        Dim peringatan As Boolean
        If txtnokk.Text = "" Then
            peringatan = False
            MessageBox.Show("No. Kartu Keluarga Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnokk.Focus()
        ElseIf txtnamakeluarga.Text = "" Then
            peringatan = False
            MessageBox.Show("Nama Kepala Keluarga Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnamakeluarga.Focus()
        ElseIf txtnama1.Text = "" Then
            peringatan = False
            MessageBox.Show("Nama Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnama1.Focus()
        ElseIf cmbkelamin1.Text = "" Then
            peringatan = False
            MessageBox.Show("Jenis Kelamin Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbkelamin1.Focus()
        ElseIf cmbdilahirkan1.Text = "" Then
            peringatan = False
            MessageBox.Show("Tempat Dilahirkan Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbdilahirkan1.Focus()
        ElseIf cmbkelahiran1.Text = "" Then
            peringatan = False
            MessageBox.Show("Tempat Kelahiran Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbkelahiran1.Focus()
        ElseIf dtplahir1.Text = "" Then
            peringatan = False
            MessageBox.Show("Tanggal Lahir Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            dtplahir1.Focus()
        ElseIf txtumur1.Text = "" Then
            peringatan = False
            MessageBox.Show("Umur Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtumur1.Focus()
        ElseIf cmbjenis.Text = "" Then
            peringatan = False
            MessageBox.Show("Jenis Kelahiran Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbjenis.Focus()
        ElseIf txtpenolong1.Text = "" Then
            peringatan = False
            MessageBox.Show("Penolong Kelahiran Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtpenolong1.Focus()
        ElseIf txtberat.Text = "" Then
            peringatan = False
            MessageBox.Show("Berat Bayi Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtberat.Focus()
        ElseIf txtpanjang.Text = "" Then
            peringatan = False
            MessageBox.Show("Panjang Bayi Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtpanjang.Focus()
        ElseIf txtnik2.Text = "" Then
            peringatan = False
            MessageBox.Show("NIK Ibu  Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnik2.Focus()
        ElseIf txtnama2.Text = "" Then
            peringatan = False
            MessageBox.Show("Nama Ibu Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnama2.Focus()
        ElseIf dtplahir2.Text = "" Then
            peringatan = False
            MessageBox.Show("Tanggal Lahir Ibu Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            dtplahir2.Focus()
        ElseIf cmbpekerjaan2.Text = "" Then
            peringatan = False
            MessageBox.Show("Pekerjaan Ibu Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbpekerjaan2.Focus()
        ElseIf txtalamat2.Text = "" Then
            peringatan = False
            MessageBox.Show("Alamat Ibu Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtalamat2.Focus()
        ElseIf cmbnegara2.Text = "" Then
            peringatan = False
            MessageBox.Show("Kewarganegaraan Ibu Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbnegara2.Focus()
        ElseIf cmbbangsa2.Text = "" Then
            peringatan = False
            MessageBox.Show("Kebangsaan Ibu Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbbangsa2.Focus()
        ElseIf dtppekawinan.Text = "" Then
            peringatan = False
            MessageBox.Show("Tanggal Pencatatan Perkawinan Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            dtppekawinan.Focus()
        ElseIf txtnik3.Text = "" Then
            peringatan = False
            MessageBox.Show("NIK Ayah Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnik3.Focus()
        ElseIf txtnama3.Text = "" Then
            peringatan = False
            MessageBox.Show("Nama Ayah Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnama3.Focus()
        ElseIf dtplahir3.Text = "" Then
            peringatan = False
            MessageBox.Show("Tanggal Lahir Ayah  Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            dtplahir3.Focus()
        ElseIf cmbpekerjaan3.Text = "" Then
            peringatan = False
            MessageBox.Show("Pekerjaan Ayah Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbpekerjaan3.Focus()
        ElseIf txtalamat3.Text = "" Then
            peringatan = False
            MessageBox.Show("Alamat Ayah Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtalamat3.Focus()
        ElseIf cmbnegara3.Text = "" Then
            peringatan = False
            MessageBox.Show("Kewarganegaraan Ayah Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbnegara3.Focus()
        ElseIf cmbbangsa3.Text = "" Then
            peringatan = False
            MessageBox.Show("Kebangsaan Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            cmbbangsa3.Focus()
        ElseIf txtnik4.Text = "" Then
            peringatan = False
            MessageBox.Show("NIK Pelapor Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnik4.Focus()
        ElseIf txtnama4.Text = "" Then
            peringatan = False
            MessageBox.Show("Nama Pelapor Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnama4.Focus()
        ElseIf txthubungan.Text = "" Then
            peringatan = False
            MessageBox.Show("Hubungan Pelapor dengan Bayi Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txthubungan.Focus()
        ElseIf txtnik5.Text = "" Then
            peringatan = False
            MessageBox.Show("NIK Saksi I Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnik5.Focus()
        ElseIf txtnama5.Text = "" Then
            peringatan = False
            MessageBox.Show("Nama Saksi II Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnama5.Focus()
        ElseIf txtnik6.Text = "" Then
            peringatan = False
            MessageBox.Show("NIK Saksi II Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnik5.Focus()
        ElseIf txtnama6.Text = "" Then
            peringatan = False
            MessageBox.Show("Nama Saksi II Belum Terisi", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtnama5.Focus()
        Else
            peringatan = True
        End If
        Return peringatan
    End Function
    Private Sub btnsimpan_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        If validasi() Then
            Call add()
            Call filtabel()
            data_kelahiran.Show()
        End If
    End Sub

    Private Sub btntutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntutup.Click
        Dim PESAN As String

        PESAN = MessageBox.Show("Terimaksih", "Exit", MessageBoxButtons.OKCancel)
        If PESAN = System.Windows.Forms.DialogResult.OK Then
            'MessageBox.Show("Terimaksih", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Close()
        End If
    End Sub

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

    End Sub


End Class
4

1 回答 1

0

请注意您是如何在您的bindingdata方法中进行查询的 - 在您创建 之后OleDbCommand,您调用Parameters.AddWithValue()以使用数据填充查询。对方法中的插入命令执行相同的操作add

isi = "INSERT INTO tblkelahiran (no_kk,nm_kk, ... , nm_saksi2) values (@no_kk,@nm_kk, ... , @nm_saksi2)"
perintah = New OleDbCommand(iki, konekOLEDB)
With perintah.Parameters
    .AddWithValue("@no_kk", txtnokk.Text)
    .AddWithValue("@nm_kk", txtnamakeluarga.Text)
    '...
    .AddWithValue("@nm_saksi2", txtnama6.Text)
End With
perintah.ExecuteNonQuery()

这不会解决问题。但是现在您可以将每个AddWithValue调用更改为一个已知值,一次一个,直到问题消失:

.AddWithValue("@no_kk", "txtnokk")

.AddWithValue("@nm_kk", "txtnamakeluarga")

等等。当您不再收到错误时,您更改的最后一项就是导致问题的项。

于 2012-11-13T19:16:20.373 回答