6 Des 2009

Tugas Pemrograman Visual II maetri sorting dan dataview

4:38 PM



hey. . kali ini aku ngpost tugas Pemrograman Visual II maetri sorting dan dataview. .!! Mungkin ini tugas termudah yang diberikan dosenku pak Indra semester ini. hehehee. .. . makanya aku bisa ngerjain sendiri.
Ini source code aku copy , tapi bukan untuk yang sudah master hanya untuk pemula !!!! Bagi yang udah expert mungkin bisa di share ilmunya disini !!!




Imports System.Data.SqlClient

Public Class Form2
    Dim xcon As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
    Dim xda As New SqlDataAdapter
    Dim xset As New DataSet
    Dim xdv As New DataView
    Dim xdt As DataTable
    Dim xposisi As Integer = 0

    Sub isicombo()
        With cmb_con
            .Items.Add("Show All")
            .Items.Add("Accounting Manager")
            .Items.Add("Assistant Sales Agent")
            .Items.Add("Assistant Sales Representative")
            .Items.Add("Marketing Assistant")
            .Items.Add("Marketing Manager")
            .Items.Add("Order Administrator")
            .Items.Add("owner")
            .Items.Add("owner/Marketing Assistant")
            .Items.Add("Sales Agent")
            .Items.Add("Sales Associate")
            .Items.Add("Sales Manager")
            .Items.Add("Sales Representative")
        End With
        With cmb_sort
            .Items.Add("Ascending")
            .Items.Add("Descending")
        End With

    End Sub

    Sub dataview()
        dt = New DataTable("Customers")
        dAdapter = New SqlDataAdapter("select * from Customers", con)
        dAdapter.Fill(dt)
        dv = dt.DefaultView
        dv.Sort = "CustomerID"
    End Sub
  
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        isicombo()
  dataview()
        DataGridView1.DataSource = xdv
        'cmb_con.DataSource = xdt
        'cmb_con.ValueMember = "ContactTitle"
        'cmb_con.DisplayMember = "ContactTitle"
        'With cmb_con.Items().Add("Show All")
        'End With
     

    End Sub



    Private Sub cmb_con_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_con.SelectedIndexChanged
       
  dataview()
  If cmb_con.Text = "Show All" Then
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "Accounting Manager" Then
            xdv.RowFilter = "ContactTitle = 'Accounting Manager'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "Assistant Sales Agent" Then
            xdv.RowFilter = "ContactTitle = 'Assistant Sales Agent'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "Assistant Sales Representative" Then
            xdv.RowFilter = "ContactTitle = 'Assistant Sales Representative'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "Marketing Assistant" Then
            xdv.RowFilter = "ContactTitle = 'Marketing Assistant'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "Marketing Manager" Then
            xdv.RowFilter = "ContactTitle = 'Marketing Manager'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "Order Administrator" Then
            xdv.RowFilter = "ContactTitle = 'Order Administrator'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "owner" Then
            xdv.RowFilter = "ContactTitle = 'owner'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "owner/Marketing Assistant" Then
            xdv.RowFilter = "ContactTitle = 'owner/Marketing Assistant'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "Sales Agent" Then
            xdv.RowFilter = "ContactTitle = 'Sales Agent'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "Sales Associater" Then
            xdv.RowFilter = "ContactTitle = 'Sales Associate'"
            DataGridView1.DataSource = xdv
        ElseIf cmb_con.Text = "Sales Manager" Then
            xdv.RowFilter = "ContactTitle = 'Sales Manager'"
            DataGridView1.DataSource = xdv
        Else
            'cmb_con.Text = "Sales Representative"
            xdv.RowFilter = "ContactTitle = 'Sales Representative'"
            DataGridView1.DataSource = xdv
        End If
    End Sub

    Private Sub cmb_sort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_sort.SelectedIndexChanged
        If cmb_sort.Text = "Ascending" Then
            xdv.Sort = "CustomerID asc"
        Else
            xdv.Sort = "CustomerID desc"
        End If
    End Sub
End Class

Tugas Ini memakai Database Northwind yang biasanya sudah tersedia di Sql Servernya. Project lengkapnya bisa di download di bawah ini. Semoga bermanfaat  *_-    jangan lupa postkan komentar kamu !!!!
thanks...!




Written by

Bukan seorang pakar ataupun praktisi profesional, hanya ingin berbagai atas esensi realita perjalanan dan mimpi yang terlihat tak bertepi.

0 komentar:

Posting Komentar

 

© 2014 Dipzt. All rights resevered. Designed by Templateism

Back To Top