Powered By Blogger

Selasa, 22 November 2011

tugas PBD


Nama/nim anggota kelonpok:
  1. M. Afnan kurniansyah/10.41010.0268
  2. M. ALi Akbar/
  3. Habibi 
Tampilan awal dari form adalah sbb:
Dan setelah memilih product ID kemudian klik display, maka tampilannya sbb:


untuk koneksi dengan database menggunakan script berikut
Public koneksi_ku As String = "data source =.\sqlexpress; database =northwind; integrated security =true"
    Dim perintah As SqlCommand
    Dim reader As SqlDataReader
    Sub categoryname()
    Dim cn As New SqlConnection(koneksi_ku)
    Dim sqlRak As String = "select categoryname from categories where categoryID = '" & cmbCategoryID.Text & "'"
    cn.Open()

pengisian combo box product id sbb
Dim cn As New SqlConnection(koneksi_ku)
        Dim sqlRak As String = "select ProductID from products"

        cn.Open()
        perintah = New SqlClient.SqlCommand
        perintah.Connection = cn
        perintah.CommandType = CommandType.Text
        perintah.CommandText = sqlRak

        reader = perintah.ExecuteReader

        While reader.Read
            cmbProductID.Items.Add(Trim(reader("ProductID")))
        End While
        reader.Close()
        perintah.Dispose()

syntax untuk mengedit product
Dim cn As New SqlConnection(koneksi_ku)
        Dim sql As String = "update products set ProductID = '" & cmbProductID.Text & "', productname = '" & txtProductName.Text & "',SupplierID = '" & cmbSupplierID.Text & "', CategoryID = '" & cmbCategoryID.Text & "', quantityperunit = '" & txtQuantity.Text & "', Unitprice = '" & txtUnitPrice.Text & "', unitsinstock = '" & txtUnitStok.Text & "', unitsonorder = '" & txtUnitOrder.Text & "', reorderlevel = '" & txtReorderLevel.Text & "', discontinued = '" & txtDiscontinued.Text & "' where productID = '" & cmbProductID.Text & "'"
        cn.Open()
        perintah = New SqlClient.SqlCommand
        perintah.Connection = cn
        perintah.CommandType = CommandType.Text
        perintah.CommandText = sql
        perintah.ExecuteNonQuery()
        perintah.Dispose()

        MsgBox("Data telah terupdate", MsgBoxStyle.Information, "Informasi")

Syntax untuk menginsert product
Dim cn As New SqlConnection(koneksi_ku)
        Dim sqlupdate As String = "insert into products values ('" & cmbProductID.Text & "', '" & txtProductName.Text & "', '" & cmbSupplierID.Text & "', '" & cmbCategoryID.Text & "', '" & txtQuantity.Text & "', '" & txtUnitPrice.Text & "', '" & txtUnitStok.Text & "', '" & txtUnitOrder.Text & "', '" & txtReorderLevel.Text & "', '" & txtDiscontinued.Text & "')"
        cn.Open()
        perintah = New SqlClient.SqlCommand
        perintah.Connection = cn
        perintah.CommandType = CommandType.Text
        perintah.CommandText = sqlupdate
        perintah.ExecuteNonQuery()
        perintah.Dispose()

        MsgBox("Data telah tersimpan", MsgBoxStyle.Information, "Informasi")

Syntax untuk delete
  Dim cn As New SqlConnection(koneksi_ku)
        Dim sqlhapus As String = " delete from products where productID='" & cmbProductID.Text & "'"
        cn.Open()
        perintah.Connection = cn
        perintah.CommandType = CommandType.Text
        perintah.CommandText = sqlhapus
        perintah.ExecuteNonQuery()
        perintah.Dispose()

        MsgBox("Data telah dihapus", MsgBoxStyle.Information, "Informasi")

Tidak ada komentar: