Sabtu, 26 Maret 2016

Coding (cari dari 2 atau lebih kategori) pada VB



Dim str As String
        'str yang akan di isi
        'cari 4 kategori
        If Me.tbjudulcari.Text.Length > 0 And Me.tbpengarangcari.Text.Length > 0 And Me.tbpenerbitcari.Text.Length > 0 And Me.tbbagiancari.Text.Length > 0 Then
            str = "select * from tbbuku where judul like '%" & tbjudulcari.Text & "%' or pengarang like '%" & tbpengarangcari.Text & "%' or penerbit like '%" & tbpenerbitcari.Text & "%' or bag like '%" & tbbagiancari.Text & "%'"
            'cari 3 kategori
        ElseIf Me.tbjudulcari.Text.Length > 0 And Me.tbpengarangcari.Text.Length > 0 And Me.tbpenerbitcari.Text.Length > 0 And Me.tbbagiancari.Text.Length <= 0 Then
            str = "select * from tbbuku where judul like '%" & tbjudulcari.Text & "%' or pengarang like '%" & tbpengarangcari.Text & "%' or penerbit like '%" & tbpenerbitcari.Text & "%'"
        ElseIf Me.tbjudulcari.Text.Length > 0 And Me.tbpengarangcari.Text.Length > 0 And Me.tbpenerbitcari.Text.Length <= 0 And Me.tbbagiancari.Text.Length > 0 Then
            str = "select * from tbbuku where judul like '%" & tbjudulcari.Text & "%' or pengarang like '%" & tbpengarangcari.Text & "%' or bag like '%" & tbbagiancari.Text & "%'"
        ElseIf Me.tbjudulcari.Text.Length <= 0 And Me.tbpengarangcari.Text.Length > 0 And Me.tbpenerbitcari.Text.Length > 0 And Me.tbbagiancari.Text.Length > 0 Then
            str = "select * from tbbuku where pengarang like '%" & tbpengarangcari.Text & "%' or penerbit like '%" & tbpenerbitcari.Text & "%' or bag like '%" & tbbagiancari.Text & "%'"
        ElseIf Me.tbjudulcari.Text.Length > 0 And Me.tbpengarangcari.Text.Length <= 0 And Me.tbpenerbitcari.Text.Length > 0 And Me.tbbagiancari.Text.Length > 0 Then
            str = "select * from tbbuku where judul like '%" & tbjudulcari.Text & "%' or penerbit like '%" & tbpenerbitcari.Text & "%' or bag like '%" & tbbagiancari.Text & "%'"
            'cari 2 kategori
            'awal 1
        ElseIf Me.tbjudulcari.Text.Length > 0 And Me.tbpengarangcari.Text.Length > 0 And Me.tbpenerbitcari.Text.Length <= 0 And Me.tbbagiancari.Text.Length <= 0 Then
            str = "select * from tbbuku where judul like '%" & tbjudulcari.Text & "%' or pengarang like '%" & tbpengarangcari.Text & "%'"
        ElseIf Me.tbjudulcari.Text.Length > 0 And Me.tbpengarangcari.Text.Length <= 0 And Me.tbpenerbitcari.Text.Length > 0 And Me.tbbagiancari.Text.Length <= 0 Then
            str = "select * from tbbuku where judul like '%" & tbjudulcari.Text & "%' or penerbit like '%" & tbpenerbitcari.Text & "%'"
        ElseIf Me.tbjudulcari.Text.Length > 0 And Me.tbpengarangcari.Text.Length <= 0 And Me.tbpenerbitcari.Text.Length <= 0 And Me.tbbagiancari.Text.Length > 0 Then
            str = "select * from tbbuku where judul like '%" & tbjudulcari.Text & "%' or bagian like '%" & tbbagiancari.Text & "%'"
            'awal 2
        ElseIf Me.tbjudulcari.Text.Length <= 0 And Me.tbpengarangcari.Text.Length > 0 And Me.tbpenerbitcari.Text.Length > 0 And Me.tbbagiancari.Text.Length <= 0 Then
            str = "select * from tbbuku where pengarang like '%" & tbpenerbitcari.Text & "%' or penerbit like '%" & tbpenerbitcari.Text & "%'"
        ElseIf Me.tbjudulcari.Text.Length <= 0 And Me.tbpengarangcari.Text.Length > 0 And Me.tbpenerbitcari.Text.Length <= 0 And Me.tbbagiancari.Text.Length > 0 Then
            str = "select * from tbbuku where pengarang like '%" & tbpengarangcari.Text & "%' or bagian like '%" & tbbagiancari.Text & "%'"
            'awal 3
        ElseIf Me.tbjudulcari.Text.Length <= 0 And Me.tbpengarangcari.Text.Length <= 0 And Me.tbpenerbitcari.Text.Length > 0 And Me.tbbagiancari.Text.Length > 0 Then
            str = "select * from tbbuku where penerbit like '%" & tbpenerbitcari.Text & "%' or bag like '%" & tbbagiancari.Text & "%'"
            'cari 1 kategori
        ElseIf Me.tbjudulcari.Text.Length > 0 And Me.tbpengarangcari.Text.Length <= 0 And Me.tbpenerbitcari.Text.Length <= 0 And Me.tbbagiancari.Text.Length <= 0 Then
            str = "select * from tbbuku where judul like '%" & tbjudulcari.Text & "%'"
        ElseIf Me.tbjudulcari.Text.Length <= 0 And Me.tbpengarangcari.Text.Length > 0 And Me.tbpenerbitcari.Text.Length <= 0 And Me.tbbagiancari.Text.Length <= 0 Then
            str = "select * from tbbuku where pengarang like '%" & tbpengarangcari.Text & "%'"
        ElseIf Me.tbjudulcari.Text.Length <= 0 And Me.tbpengarangcari.Text.Length <= 0 And Me.tbpenerbitcari.Text.Length > 0 And Me.tbbagiancari.Text.Length <= 0 Then
            str = "select * from tbbuku where penerbit like '%" & tbpenerbitcari.Text & "%'"
        ElseIf Me.tbjudulcari.Text.Length <= 0 And Me.tbpengarangcari.Text.Length <= 0 And Me.tbpenerbitcari.Text.Length <= 0 And Me.tbbagiancari.Text.Length > 0 Then
            str = "select * from tbbuku where bag like '%" & tbbagiancari.Text & "%'"
        End If
        'str belum di isi, kondisi str NULL, kondisi str di atas terpenuhi

Tidak ada komentar:

Posting Komentar