form2


Public Class frmtambahdata
    Dim connsql As SqlClient.SqlConnection
    Dim dataadapteranggota As SqlClient.SqlDataAdapter
    Dim tabelanggota As New DataTable
    Dim cmdtabelanggota As SqlClient.SqlCommandBuilder
    Dim strkoneksi As String
    Dim recordanggota As DataRow
    Dim posisirecord As Integer

    Private Sub frmtambahdata_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        connsql.Close()
        connsql.Dispose()
    End Sub

    Private Sub frmtambahdata_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        strkoneksi = "Data Source=JAHIR-19D23153D\SQLEXPRESS;Initial " _
         & "Catalog=dbsimpin;Integrated Security=True"
        'bukakoneksi()
        connsql = New SqlClient.SqlConnection(strkoneksi)
        connsql.Open()
        dataadapteranggota = New SqlClient.SqlDataAdapter("select noanggota,namaanggota,alamat," _
                    & "jeniskelamin from tbanggota", connsql)
        dataadapteranggota.Fill(tabelanggota)
        cmdtabelanggota = New SqlClient.SqlCommandBuilder(dataadapteranggota)
        recordanggota = tabelanggota.Rows(0)
        txtnoanggota.Text = ""
        txtnama.Text = ""
        txtalamat.Text = ""
        cmbkelamin.Text = ""
    End Sub

    Private Sub cmdbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdbatal.Click
        Me.Close()
    End Sub

    Private Sub cmdbuat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdbuat.Click
        If txtnoanggota.Text <> "" And txtnama.Text <> "" And txtalamat.Text <> "" _
           And cmbkelamin.Text <> "" Then
            tabelanggota.Rows.Add()
            posisirecord = tabelanggota.Rows.Count - 1
            recordanggota = tabelanggota.Rows(posisirecord)
            recordanggota("noanggota") = txtnoanggota.Text
            recordanggota("namaanggota") = txtnama.Text
            recordanggota("alamat") = txtalamat.Text
            recordanggota("jeniskelamin") = cmbkelamin.Text
            'recordanggota("tgllahir") = Now()
            dataadapteranggota.Update(tabelanggota)
            Me.Close()
        Else
            MsgBox("Data harus diisi semua", MsgBoxStyle.Information, "Informasi")
        End If
    End Sub
End Class
Share this article :
 

Post a Comment

 
Support : Creating Website | anak sholeh | Anak sholeh
Copyright © 2011. Coretan Anak Sholeh - All Rights Reserved
Template Created by Creating Website Published by anak sholeh
Proudly powered by Blogger