Coding

Imports System.Data.SqlClient

=============================================================================
    Public conn As SqlConnection
    Public cmd As SqlCommand
    Public rd As SqlDataReader
    Public da As SqlDataAdapter
    Public ds As DataSet
    Public str As String

=============================================================================
            str = "Data Source=SILENCE\SQLEXPRESS; Initial Catalog=login; Integrated Security=True"
            conn = New SqlConnection(str)
            conn.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

=============================================================================
Public Class Form1
    Private Sub cmdOk_Click(sender As Object, e As EventArgs) Handles cmdOk.Click
        If txtUid.Text = "" Or txtPswd.Text = "" Then
            MsgBox("Data Belum Lengkap!", MsgBoxStyle.Exclamation)
            Exit Sub
        Else
            Call opendb()
            cmd = New SqlCommand("select * from userdata where username='" & txtUid.Text & "' and password='" & txtPswd.Text & "'", conn)
            rd = cmd.ExecuteReader
            rd.Read()
            If rd.HasRows Then
                Me.Hide()
                frmMenu.Show()
            Else
                MsgBox("Username atau Password Salah!", MsgBoxStyle.Critical, "Erorr")
            End If
        End If
    End Sub

=============================================================================
        ds = New DataSet
        da.Fill(ds, "tb_penumpang")
        dgvPenumpang.DataSource = ds.Tables("tb_penumpang")
    End Sub

=============================================================================
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If txtidpng.Text = "" Or txtnama.Text = "" Or txtnotelp.Text = "" Or txtalamat.Text = "" Then
            MsgBox("Data belum lengkap!", MsgBoxStyle.Exclamation)
            Exit Sub
        Else
            Call koneksi()
            Dim tambah As String = "insert tb_penumpang Values ('" & txtidpng.Text & "','" & txtnama.Text & "','" & txtnotelp.Text & "','" & txtalamat.Text & "')"
            cmd = New SqlCommand(tambah, conn)
            cmd.ExecuteNonQuery()
            MsgBox("Data berhasil di tambahkan!", MsgBoxStyle.Information)
            Call bersih()
            Call tampil()
        End If
    End Sub

============================================================================
    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        If txtidpng.Text = "" Or txtnama.Text = "" Or txtnotelp.Text = "" Or txtalamat.Text = "" Then
            MsgBox("Pilih data yang akan di ubah!", MsgBoxStyle.Exclamation)
            Exit Sub
        Else
            Call koneksi()
            Dim edit As String = "update tb_penumpang set Nama='" & txtnama.Text & "',No_Telp='" & txtnotelp.Text & "',Alamat='" & txtalamat.Text & "' where Id_Penumpang='" & txtidpng.Text & "'"
            cmd = New SqlCommand(edit, conn)
            cmd.ExecuteNonQuery()
            MsgBox("Data berhasil di ubah!", MsgBoxStyle.Information)
            Call bersih()
            Call tampil()
        End If
    End Sub

===========================================================================
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If txtidpng.Text = "" Or txtnama.Text = "" Or txtnotelp.Text = "" Or txtalamat.Text = "" Then
            MsgBox("Pilih data yang akan dihapus!", MsgBoxStyle.Exclamation)
            Exit Sub
        Else
            Call koneksi()
            If MessageBox.Show("Yakin akan dihapus ?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
                Dim hapus As String = "delete from tb_penumpang where Id_Penumpang= '" & txtidpng.Text & "'"
                cmd = New SqlCommand(hapus, conn)
                cmd.ExecuteNonQuery()
                MsgBox("Data berhasil di Hapus!", MsgBoxStyle.Information)
            End If
            Call bersih()
            Call tampil()
        End If
    End Sub


===========================================================================
    Private Sub dgvPenumpang_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvPenumpang.CellClick
        Dim i As Integer
        i = Me.dgvPenumpang.CurrentRow.Index
        With dgvPenumpang.Rows.Item(i)
            txtidpng.Text = .Cells(0).Value
            txtnama.Text = .Cells(1).Value
            txtnotelp.Text = .Cells(2).Value
            txtalamat.Text = .Cells(3).Value
        End With
    End Sub
End Class
============================================================================
        ElseIf ComboBox2.Text = "NIS" Then
            da = New SqlDataAdapter("select * from tb_siswa where Nis like '%" & TextBox4.Text & "%'", conn)
            ds = New DataSet
            da.Fill(ds, "tb_siswa")
            DataGridView1.DataSource = ds.Tables("tb_siswa")
============================================================================

                da = New SqlDataAdapter("select * from tb_siswa order by Nama desc", conn)
                ds = New DataSet
                da.Fill(ds, "tb_siswa")
                DataGridView1.DataSource = ds.Tables("tb_siswa")

0 comments:

Post a Comment