Kamis, 06 April 2017

Mengaplikasikan Database Normalisasi Pada ASP.NET (UTS Lab SMBD)

Tahapan Normalisasi

1NF
Table_RentalMobil (ID_Penyewa, Nama_Penyewa, NamaMobil_Disewa, MerkMobil_Disewa, ID_Merk, Tingkatan_Harga, Sewa_Perhari)

2NF
Table_RentalMobil (ID_Penyewa, Nama_Penyewa, ID_Merk, Tingkatan_Harga)
Table_TingkatHarga (Tingkatan_Harga, Sewa_Hari)
Table_Merk (ID_Merk, MerkMobil_Disewa)


3NF sama dengan 2NF


Screenshot








Source Code Manipulasi Data

Imports System.Data
Imports System.Data.OleDb

Public Class WebForm2
    Inherits System.Web.UI.Page

    Public constring As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
    Public oConn As New OleDbConnection(constring)
    Public oTbl As New DataTable
    Public xReader As OleDbDataReader

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    'Insert
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim sql As String = "INSERT INTO Table_RentalMobil VALUES ('" & TxtIDPenyewa.Text & "','" & txtNama.Text & "','" & txtIDMerk.Text & "','" & txtTingkatHarga.Text & "')"
        Dim oCmd As New OleDbCommand
        oConn.Open()
        oCmd.Connection = oConn
        oCmd.CommandText = sql
        oCmd.ExecuteNonQuery()
    End Sub

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Response.Redirect("WebForm1.aspx")
    End Sub
    'Delete
    Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim hapus = MsgBox("Konfirmasi", MsgBoxStyle.YesNo, "Hapus")

        If hapus = vbYes Then
            oConn.Close()
            oConn.Open()
            Dim delet As String = "DELETE FROM Table_RentalMobil where ID_Penyewa =" + TxtIDPenyewa.Text + ""
            Dim oCmd As New OleDbCommand
            oConn.Close()
            oConn.Open()
            oCmd.Connection = oConn
            oCmd.CommandText = delet
            oCmd.ExecuteNonQuery()
            MsgBox("Sudah terhapus", vbArchive)

            TxtIDPenyewa.Text = ""
            txtNama.Text = ""
            txtIDMerk.Text = ""
            txtTingkatHarga.Text = ""

        End If

    End Sub
    'Search
    Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        oConn.Close()
        oConn.Open()
        Dim Cmd As New OleDbCommand("SELECT * FROM Table_Rental where ID_Penyewa =" + TxtIDPenyewa.Text + "", oConn)
        xReader = Cmd.ExecuteReader
        If xReader.HasRows Then
            xReader.Read()
            txtNama.Text = xReader("Nama_Penyewa")
            txtIDMerk.Text = xReader("ID_Merk")
            txtTingkatHarga.Text = xReader("Tingkatan_Harga")


        Else
            MsgBox("Kode Buku Tidak Ada")
            TxtIDPenyewa.Text = ""
            txtNama.Text = ""
            txtIDMerk.Text = ""
            txtTingkatHarga.Text = ""

            Exit Sub
        End If
        xReader.Close()


    End Sub
    'Update
    Protected Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Dim sql As String = " UPDATE Table_RentalMobil set Nama_Penyewa  ='" & txtNama.Text & "', ID_Merk = " & txtIDMerk.Text & ", Tingkatan_Harga = '" & txtTingkatHarga.Text & "' where ID_Penyewa = " & TxtIDPenyewa.Text & ""

        Dim oCmd As New OleDbCommand
        oConn.Close()
        oConn.Open()
        oCmd.Connection = oConn
        oCmd.CommandText = sql

        oCmd.ExecuteNonQuery()

    End Sub
End Class

1 komentar:

  1. Source code ini, fungsinya untuk apa ya?: Public constring As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

    saya coba kok gagal, atau ada tambahan source code lainnya?

    BalasHapus