Skip to main content

DML dengan Database SQL 2000 - 03

Dear agan-agan sekalian para pecinta VB terutama bagi yang baru saja beralih dari VB 6 ke VB.Net seperti saya ini.

nah kali ini kita akan coding dengan database SQL Server 2000, naik level dari tutorial sebelumnya yang masih menggunakan database Ms.Access.

silahkan membuat form seperti di atas dengan properti ToolStrip, DatagridView, Textbox dan Label. untuk penamaan propertinya silahkan mengikuti coding dibawah atau menamakannya dengan nama lain, intinya paham dan aplikasi bisa running.

======================================================

Private Sub DATA_DIVISI()

  Call KONEKSI()

  DS = New DataSet
  TABEL = "SELECT * FROM TABEL_DIVISI"
  GRID = New OleDb.OleDbDataAdapter(TABEL, DATABASE)
  GRID.Fill(DS, "TABEL_DIVISI")

  Dim GRIDVIEW As New DataView(DS.Tables("TABEL_DIVISI"))
  DGDIVISI.DataSource = GRIDVIEW

  DGDIVISI.Columns(0).Width = 50
  DGDIVISI.Columns(1).Width = 190

  End Sub
======================================================
  'Koding AutoNumber ini agak naik LEVEL lah..
  Private Sub NOMOR_DIVISI()

  Call KONEKSI()

  TAMPIL.Connection = DATABASE
  TAMPIL.CommandType = CommandType.Text
  TAMPIL.CommandText = "SELECT * FROM TABEL_DIVISI"
  TAMPILKAN = TAMPIL.ExecuteReader

  If TAMPILKAN.HasRows = True Then

  While TAMPILKAN.Read()
  'NOMORDIVISI = Nama FIELD DATABASE
  TxtNOMOR.Text = TAMPILKAN("NOMORDIVISI")
  End While

  TxtNOMOR.Text = TxtNOMOR.Text + 1

  If Len(TxtNOMOR.Text) = 1 Then
  TxtNOMOR.Text = "00" & TxtNOMOR.Text & ""
  ElseIf Len(TxtNOMOR.Text) = 2 Then
  TxtNOMOR.Text = "0" & TxtNOMOR.Text & ""
  ElseIf Len(TxtNOMOR.Text) = 3 Then
  TxtNOMOR.Text = "" & TxtNOMOR.Text & ""
  Else
  TxtNOMOR.Text = TxtNOMOR.Text
  End If

  TxtDIVISI.Focus()

  Else
  TxtNOMOR.Text = "001"
  End If

  End Sub
=====================================================
  Private Sub KUNCI()

  TxtNOMOR.Enabled = False
  TxtDIVISI.Enabled = False

  End Sub
=====================================================
  Private Sub BUKA()

  TxtDIVISI.Enabled = True

  End Sub
=====================================================
  Private Sub KOSONG()

  TxtNOMOR.Text = ""
  TxtDIVISI.Text = ""

  TxtDIVISI.Focus()

  BTNINPUT.Enabled = True
  BTNUBAH.Enabled = False
  BTNHAPUS.Enabled = False

  TOOLINPUT.Text = "INPUT"
  TOOLUBAH.Text = "UBAH"
  TOOLHAPUS.Text = "HAPUS"
  TOOLEXIT.Text = "EXIT"

  Call DATA_DIVISI()

  End Sub
======================================================
  Private Sub FORM_DIVISI_02_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated

  Call KOSONG()
  Call KUNCI()

  TxtNOMOR.Enabled = False
  TxtDIVISI.CharacterCasing = CharacterCasing.Upper
  TxtDIVISI.Focus()

  End Sub
=====================================================
  Private Sub BTNINPUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNINPUT.Click

  If TOOLINPUT.Text = "INPUT" Then

  Call DATA_DIVISI()
  Call NOMOR_DIVISI()
  Call BUKA()

  TOOLINPUT.Text = "SIMPAN"
  TOOLEXIT.Text = "BATAL"

  TxtDIVISI.Focus()

  ElseIf TOOLINPUT.Text = "SIMPAN" Then

  If TxtDIVISI.Text = "" Then
  MsgBox("PASTIKAN ANDA MENGISI DATA !!", MsgBoxStyle.Information, "WIRAT")
  Call KOSONG()
  Call KUNCI()

  Else

  Try
  Call KONEKSI()

  DMLSQL.Connection = DATABASE
  DMLSQL.CommandType = CommandType.Text
  DMLSQL.CommandText = "INSERT INTO TABEL_DIVISI VALUES('" & TxtNOMOR.Text & "','" & TxtDIVISI.Text & "')"
  DMLSQL.ExecuteNonQuery()

  MsgBox("DATA TERSIMPAN !!", MsgBoxStyle.Information, "WIRAT")

  Call KOSONG()
  Call KUNCI()

  Catch ex As Exception
  MsgBox(ex.ToString)
  End Try
  End If
  End If

  End Sub
=====================================================
  Private Sub BTNEXIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNEXIT.Click

  If TOOLEXIT.Text = "BATAL" Then
  Call KOSONG()
  Call KUNCI()
  Else
  Me.Close()
  End If
  End Sub
=====================================================
  Private Sub DGDIVISI_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DGDIVISI.DoubleClick

  Try
  TxtNOMOR.Text = DGDIVISI.SelectedCells(0).Value
  TxtDIVISI.Text = DGDIVISI.SelectedCells(1).Value

  BTNINPUT.Enabled = False
  BTNUBAH.Enabled = True
  BTNHAPUS.Enabled = True

  Catch ex As Exception
  MsgBox(ex.ToString)
  End Try

  End Sub
======================================================
  Private Sub BTNUBAH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNUBAH.Click

  If TOOLUBAH.Text = "UBAH" Then

  TOOLUBAH.Text = "OK"
  TOOLEXIT.Text = "BATAL"

  Call BUKA()

  TxtDIVISI.Focus()

  ElseIf TOOLUBAH.Text = "OK" Then

  If TxtDIVISI.Text = "" Then
  MsgBox("PASTIKAN DATA UNTUK DIUBAH", MsgBoxStyle.Exclamation, "WIRAT")
  Else
  'Dim TANYA As String = MsgBox("YAKIN AKAN MERUBAH DATA " & TxtNOMOR.Text & " ??", MsgBoxStyle.YesNo, "WIRAT")
  'If TANYA = vbYes Then
  'If MsgBox("YAKIN AKAN MERUBAH DATA " & TxtNOMOR.Text & " ??", MsgBoxStyle.YesNo, "WIRAT") = MsgBoxResult.Yes Then
  Try
  Call KONEKSI()

  DMLSQL.Connection = DATABASE
  DMLSQL.CommandType = CommandType.Text
  DMLSQL.CommandText = "UPDATE TABEL_DIVISI SET DIVISI='" & TxtDIVISI.Text & "'" & _
  "WHERE NOMORDIVISI ='" & TxtNOMOR.Text & "'"
  DMLSQL.ExecuteNonQuery()

  Call KOSONG()
  MsgBox("DATA TELAH DI UBAH !!", MsgBoxStyle.Information, "WIRAT")

  Catch ex As Exception
  MsgBox(ex.ToString)
  End Try
  'Else
  'Exit Sub
  'End If

  End If

  End If

  End Sub
======================================================
  Private Sub BTNHAPUS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNHAPUS.Click

  'If MsgBox("YAKIN HAPUS DATA " & TxtNOMOR.Text & " ?? ", MsgBoxStyle.OkCancel, "WIRAT") = MsgBoxResult.Ok Then

  Try

  Call KONEKSI()
  DMLSQL.Connection = DATABASE
  DMLSQL.CommandType = CommandType.Text
  DMLSQL.CommandText = "DELETE FROM TABEL_DIVISI WHERE NOMORDIVISI='" & TxtNOMOR.Text & "'"
  DMLSQL.ExecuteNonQuery()

  Call KOSONG()
  MsgBox("DATA TELAH DI HAPUS !!", MsgBoxStyle.Information, "WIRAT")

  Catch ex As Exception
  MsgBox(ex.ToString)
  End Try

  'Else
  'Exit Sub
  'End If
   
  End Sub

Comments

Popular posts from this blog

CheckBox dalam DataGridView VB.Net

Pada saat membuat aplikasi (VB.Net) untuk materi skripsi, terbesit bagaimana cara baru untuk memberikan hak akses user secara dinamis pada sistem. setelah dicoba dengan tanya-tanya. akhirnya bisa mendapatkan cara itu... wah sesuatu banget dah.... inti dari posting ini hanya pada barisan kode berikut : Private Sub BtnSIMPAN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSIMPAN.Click         Dim Y As String = Mid(CmbUSER.Text, 1, 7)         Dim iROW As Integer         Dim AKSES As String         For iROW = 0 To DGVSample.Rows.Count - 1             'AksesBox = Nama CheckBox yang ada di DatagridView             If DGVSample.Rows(iROW).Cells("AksesBox").Value Then                 AKSES = "1"             Else                 AKSES = "0"             End If             'Class Proses DML (Simpan Data)             xSIMPAN.SIMPAN_AKSES(Y, DGVSample.Rows(iROW).Cells(1).Value, AKSES)         N

LDAP In VB.Net

hey there friends,  here is this i would like to share another simple code in developing an application in VB.Net by now i would like to share how the way to use a LDAP (Lightweight Directory Access Protocol). at the time i need to develop a system which needs to use login user using domain user (ex: peoplename@company.co.id) no longer using user level in database. it is so confused to me to make it real at the time, because i never make it before. but this is the way how i make it happened. just make a simple form as below : next level : add another reference in your visual studio project (System.DirectoryService.dll) next : make a new class Imports System Imports System.Text Imports System.Collections Imports System.Security.Principal Imports System.DirectoryServices Public Class LDAPControlClass     Private NamaDomain As String = "company.co.id"     Private MemberOf As New List(Of String)     Public Function LoginLDAP(ByVal Username