hasil belajar siswa

koneksi :
Imports System.Data.SqlClient
Module config
    Public cn As New SqlConnection
    Public cmd As New SqlCommand
    Sub opendb()
        cn.ConnectionString = "Data Source=LIA-PC\SQLEXPRESS;Initial Catalog=db_laporan_data_siswa;Integrated Security=True"
        cn.Open()
    End Sub
End Module

Imports System.Data.SqlClient
Public Class frmsiswa
    Dim cn As New SqlConnection
    Dim cmd As New SqlCommand
    Sub BukaKoneksi()
        cn.ConnectionString = "Data Source=LIA-PC\SQLEXPRESS;Initial Catalog=db_laporan_data_siswa;User ID=sa;Password=sa2012"
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
    End Sub
    Sub TampilData()
        cmd.Connection = cn
        cmd.CommandText = "SELECT * FROM tb_siswa"
        Dim rd As SqlDataReader = cmd.ExecuteReader
        Dim dt As New DataTable

        dt.Load(rd)
        dgvsiswa.DataSource = dt
    End Sub
    Sub Bersih()
        Txtnisn.Clear()
        txtnamasiswa.Clear()
        txtalamatsiswa.Clear()

    End Sub
    Private Sub frmsiswa_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        KodeKompetensiKeahlian()
        BukaKoneksi()
        TampilData()
        tanggallahir.CustomFormat = "dd/MM/yyyy"
    End Sub
    Sub KodeKompetensiKeahlian()
        CbkodeKK.Items.Add("KK01")
        CbkodeKK.Items.Add("KK02")
        CbkodeKK.Items.Add("KK03")
        CbkodeKK.Items.Add("KK04")
        CbkodeKK.Items.Add("KK05")
        CbkodeKK.Items.Add("KK06")
        CbkodeKK.Items.Add("KK07")
        CbkodeKK.Items.Add("KK08")
        CbkodeKK.Items.Add("KK09")
        CbkodeKK.Items.Add("KK10")
    End Sub

    Private Sub dgvsiswa_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvsiswa.CellContentClick

    End Sub

    Private Sub dgvsiswa_DoubleClick(sender As Object, e As EventArgs) Handles dgvsiswa.DoubleClick
        Txtnisn.Text = dgvsiswa.SelectedCells(0).Value
        CbkodeKK.Text = dgvsiswa.SelectedCells(1).Value
        txtnamasiswa.Text = dgvsiswa.SelectedCells(2).Value
        txtalamatsiswa.Text = dgvsiswa.SelectedCells(3).Value
        tanggallahir.Value = dgvsiswa.SelectedCells(4).Value
        txtfoto.Text = dgvsiswa.SelectedCells(5).Value
    End Sub

    Private Sub Btnbrowser_Click(sender As Object, e As EventArgs) Handles Btnbrowser.Click
        On Error Resume Next
        OpenFileDialog1.Filter = "JPG Files(*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|GIF Files(*.gif)|*.gif|PNG Files(*.png)|*.png|BMP Files(*.bmp)|*.bmp|TIFF Files(*.tiff)|*.tiff"
        OpenFileDialog1.FileName = ""
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Image = New Bitmap(OpenFileDialog1.FileName)
            Btnbrowser.Enabled = True

            txtfoto.Text = OpenFileDialog1.FileName
            PictureBox1.Image = Image.FromFile(txtfoto.Text)
        End If

    End Sub
    Private Sub Btnhapus_Click_1(sender As Object, e As EventArgs) Handles Btnhapus.Click
        cmd.Connection = cn
        cmd.CommandText = "DELETE from tb_siswa where nama_siswa = '" & txtnamasiswa.Text & "'"
        cmd.ExecuteNonQuery()
        MessageBox.Show("Data Telah Terhapus")
        TampilData()
        Bersih()
    End Sub

    Private Sub Btnubah_Click_1(sender As Object, e As EventArgs) Handles Btnubah.Click
        cmd.Connection = cn
        cmd.CommandText = "UPDATE tb_siswa SET kode_kk = '" & CbkodeKK.Text & "', nama_siswa = '" & txtnamasiswa.Text & "', alamat_siswa = '" & txtalamatsiswa.Text & "', tgl_lahir = '" & tanggallahir.Value & "', foto_siswa = '" & txtfoto.Text & "' WHERE NISN = '" & Txtnisn.Text & "'"
        cmd.ExecuteNonQuery()
        MessageBox.Show("Data Terupdate")
        TampilData()
        Bersih()
    End Sub

    Private Sub Btnsimpan_Click_1(sender As Object, e As EventArgs) Handles Btnsimpan.Click
        cmd.Connection = cn
        cmd.CommandText = "INSERT INTO tb_siswa VALUES ('" & Txtnisn.Text & "','" & CbkodeKK.Text & "','" & txtnamasiswa.Text & "','" & txtalamatsiswa.Text & "','" & tanggallahir.Value & "','" & txtfoto.Text & "')"
        cmd.ExecuteNonQuery()
        MessageBox.Show("Data berhasil tersimpan")
        TampilData()
        Bersih()
    End Sub
End Class

login
Imports System.Data.SqlClient
Public Class frmlogin

    Private Sub Btnlogin_Click(sender As Object, e As EventArgs) Handles Btnlogin.Click
        Dim cn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim rd As SqlDataReader

        cn.ConnectionString = "Data Source=LIA-PC\SQLEXPRESS;Initial Catalog=db_laporan_data_siswa;Integrated Security=True"
        cmd.Connection = cn
        cn.Open()
        cmd.Connection = cn
        cmd.CommandText = "SELECT password FROM tb_login WHERE password = '" & Txtuser.Text & "' AND password ='" & Txtpassword.Text & "'"
        rd = cmd.ExecuteReader

        If rd.HasRows Then
            Form2.Show()
        Else
            MessageBox.Show("Data salah")
        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub frmlogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        opendb()
    End Sub

    Private Sub Btncancel_Click(sender As Object, e As EventArgs) Handles Btncancel.Click
        Me.Close()
    End Sub
End Class

up