FUNGSI SIMPAN DINAMIS PADA VB.NET

FUNGSI SIMPAN DINAMIS PADA VB.NET

Create: nadir3011 | Rabu, 05 November 2014 | 23:09:12 WITA | dibaca: 5488

ASSALAMUALAIKUM WR WB

SALAM LOGIKA 

 

Berikut ini hasil rangkuman yang sudah dipelajari, jadi buat teman-teman yang ingin membuat fungsi simpan secara dinamis dapat menggunakan contoh algoritma query dinamis simpan dalam visual basic.net

Untuk penjelasan dari sorce code fungsi simpan dinamis akan dijelaskan berupa komentar pada listingnya.

 

 

Imports System.Data.SqlClient

Imports MySql.Data.MySqlClient

Imports System.Data.OleDb

Imports AkiLL.pesan 'Class variabel pesan yang akan kita gunakan pada saat proses simpan dieksekusi

 

Public Class simpan

    Inherits GlobalVariabel

 

    Private Sub x()

        fieldku = simpan("nmtabelku", " ", "", "", "")

        QuerySimpanSql(fieldku(0), 0)

    End Sub

 

    Public Shared Sub QuerySimpanSql(ByRef sqlQuery As String, Optional ByRef pp As Byte = 1)

        Query = sqlQuery

        AksiSimpanSql(pp)

    End Sub

 

    Public Shared Sub QuerySimpanMySql(ByRef sqlQuery As String, Optional ByRef pp As Byte = 1)

        Query = sqlQuery

        AksiSimpanMySql(pp)

    End Sub

 

    Public Shared Sub QuerySimpanOleDb(ByRef sqlQuery As String, Optional ByRef pp As Byte = 1)

        Query = sqlQuery

        AksiSimpanOleDb(pp)

    End Sub

 

    Public Shared Sub AksiSimpanMySql(Optional ByRef angka As Byte = 1)

        If (angka = 1) Then

            Try

                connMySql.Open()

                cmdMySql = New MySqlCommand(Query, connMySql)

                cmdMySql.ExecuteNonQuery()

                TampilPesanSuksesSimpan()

            Catch ex As Exception

                TampilPesanTidakSuksesSimpan()

            Finally

                connMySql.Close()

            End Try

        ElseIf (angka = 0) Then

            Try

                connMySql.Open()

                cmdMySql = New MySqlCommand(Query, connMySql)

                cmd.ExecuteNonQuery()

            Catch ex As Exception

 

            Finally

                connMySql.Close()

            End Try

        End If

    End Sub

 

    Public Shared Sub AksiSimpanSql(Optional ByRef angka As Byte = 1)

        If (angka = 1) Then

            Try

                conn.Open()

                cmd = New SqlCommand(Query, conn)

                cmd.ExecuteNonQuery()

                TampilPesanSuksesSimpan()

            Catch ex As Exception

                TampilPesanTidakSuksesSimpan()

            Finally

                conn.Close()

            End Try

        ElseIf (angka = 0) Then

            Try

                conn.Open()

                cmd = New SqlCommand(Query, conn)

                cmd.ExecuteNonQuery()

            Catch ex As Exception

 

            Finally

                conn.Close()

            End Try

        End If

    End Sub

 

    Public Shared Sub AksiSimpanOleDb(Optional ByRef angka As Byte = 1)

        If (angka = 1) Then

            Try

                connOle.Open()'Peringtah untuk membuka koneksi pada database

                cmdOle = New OleDbCommand(Query, connOle) 'Perintah query yang akan di eksekusi setelah variabel query diberikan nilai

                cmdOle.ExecuteNonQuery()

                TampilPesanSuksesSimpan()'Sebuah class yang sudah dibuat dan telah di import pada bagian atas class ini

            Catch ex As Exception

                TampilPesanTidakSuksesSimpan()

            Finally

                connOle.Close()

            End Try

        ElseIf (angka = 0) Then

            Try

                connOle.Open()

                cmdOle = New OleDbCommand(Query, connOle)

                cmdOle.ExecuteNonQuery()

                'TampilPesanSuksesSimpan()

            Catch ex As Exception

                'TampilPesanTidakSuksesSimpan()

            Finally

                connOle.Close()

            End Try

        End If

    End Sub

 

    'Dibawah ini adalah fungsi dalam membuat listing query yang dijadikan string setelah di

    Public Shared Function simpan(ByVal nmtbl As String, ByVal ParamArray args() As Object) As String()

        Dim hasil(0) As String

        Dim hsl As String

        Dim s As Byte

        hsl = "insert into " + nmtbl + " values('"

 

        Dim i As Integer

        s = UBound(args) 'Ubound maksudnya menghitung jumlah index dalam variabel args()

        For i = 0 To UBound(args)

            If s <> i Then

                Try

                    hasil(0) = hasil(0) + args(i) + "','"

                Catch ex As Exception

                    hasil(0) = hasil(0) + args(i).ToString + "','"

                End Try

            Else

                Try

                    hasil(0) = hasil(0) + args(i) + "'"

                Catch ex As Exception

                    hasil(0) = hasil(0) + args(i).ToString + "'"

                End Try

            End If

        Next i

        hasil(0) = hsl + hasil(0) + ")"

        Return hasil

    End Function

End Class

 

Jadi, untuk kesimpulannya diatas proses penyimpanan kedalam database hanya bisa menggunakan database access, mysql, dan sql server.

Untuk penggunaannya tinggal disesuaikan sesuai kebutuhan. 

Sekian dulu materi kali ini sekian dan terima kasih.

 

WASSALAMUALAIKUM WR WB 



10 KOMENTAR

wsc biolo | 13 November 2014 || 09:58:18
" samgat bagus beritanya "
gula ampuh | 27 November 2014 || 10:11:55
" salam blogger "
jamu pelangsing | 27 November 2014 || 10:17:26
" sukses selalu "
pelangsing wsc biolo | 14 Maret 2015 || 09:38:02
" te ngartos abimah naon "
jamu pelangsing badan | 14 Maret 2015 || 09:38:59
" rumit sekali "
You TV Player Official | 09 Agustus 2017 || 13:03:30
" You are downloading You TV Player Latest APK v10.6 (122). Download You TV Player for PC and Run it on Windows 7/8/8.1/10 & Mac OS. It's very easy to install You TV Player iPhone App with the help of guide here. "
is mobro safe | 03 September 2017 || 20:36:10
" <a href="https://mobdropcwindows.co/is-mobdro-legal-and- safe/">is mobro safe</a>Mobdro is such kind of platform where you can stream all the videos "
Towelroot Apk Android 4.4.2 | 07 September 2017 || 20:31:33
" Thanks for this post!! it was great reading this article! i would like to know more!! keep posting!! This post was very informative and helpful!! Good quality content!! You can now get the best rooting app for all devices!! Towelroot Apk This is one of the most efficient and safe apk for rooting!! Also the best rated app for 2017! Check Out Towelroot "
dealer honda solo | 14 September 2017 || 15:27:43
" rumit "
Bootstrap Themes | 06 Oktober 2017 || 12:52:11
" Thank you for the Well detail article one of the best article i have ever read. "



ISI KOMENTAR

NAMA

WEBSITE

KOMENTAR


Captcha Sepakbola
Apakah anda manusia?Lebih baik lagi kalau anda menyukai sepak bola
Sebutkan pemain sepak bola disamping:

Captcha Sepakbola by codingwear








  • $DCC = NEW XXI("Solidaritas","Loyalitas","Kualitas");
  • PELATIHAN KAMPUS
  • Pelatihan Komputer (DIGITAL SCHOOL)
  • Study Tour GoTv
  • IT FUN