Minggu, 22 Mei 2011

Pertemuan 13 dan 14 Koneksi Database



Imports System.Data
Imports System.Data.Sql

Module Koneksidatabase
    Public S1TI4AK As New OleDb.OleDbConnection
    'berfungsi untuk koneksi antar vb.net
    Public Tampil As New OleDb.OleDbCommand
    'berfungsi memberikan fasilitas untuk perintah2 query
    Public Tampil2 As New OleDb.OleDbCommand
    'berfungsi menyimpan data/hasil dari koneksi untuk sementara
    Public Tampilkan As OleDb.OleDbDataReader
    'berfungsi membuat variable untuk menampilakan sebuah data dalam grid
    Public Grid As New OleDb.OleDbDataAdapter
    Public Ds As New DataSet
    Public Table, hasilcek As String
    Public record As New BindingSource
    Public noo As Integer
    Public DMLSql As New OleDb.OleDbCommand
    Public Sub Koneksi()
        Try
            S1TI4AK.Close()
            'Server
            'Database.ConnectionString = "Provider=SQLOLEDB.1;Password=;Persist Security Info = True; User ID=sa; Initial Catalog=TI4K;Data Source=192.168.1.102"
            'Lokal
            S1TI4AK.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info = False; Initial Catalog=S1TI4AK;Data Source=;"
            S1TI4AK.Open()
        Catch ex As Exception
            MsgBox("Koneksi belum berhasil")
        End Try
        MsgBox("Koneksi berhasil")
    End Sub
End Module
Public Class LoginForm1

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If UsernameTextBox.Text = "Dwi Utomo" And PasswordTextBox.Text = "kevin2009" Then
            MDIParent1.Show()
            Me.Visible = False
        Else
            MsgBox("login gagal, silakan ulangi lagi")
        End If
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub




 LOGIN
   
    Private Sub UsernameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsernameTextBox.TextChanged

    End Sub

    Private Sub PasswordTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasswordTextBox.TextChanged

    End Sub
End Class


Imports System.Windows.Forms

Public Class MDIParent1

    Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
        Form2.Show()
    End Sub

    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click
        Form3.Show()
    End Sub

    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"

        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = SaveFileDialog.FileName
            ' TODO: Add code here to save the current contents of the form to a file.
        End If
    End Sub


    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CutToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CopyToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PasteToolStripMenuItem.Click
        'Use My.Computer.Clipboard.GetText() or My.Computer.Clipboard.GetData to retrieve information from the clipboard.
    End Sub

    Private Sub ToolBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ToolBarToolStripMenuItem.Click
        Me.ToolStrip.Visible = Me.ToolBarToolStripMenuItem.Checked
    End Sub

    Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles StatusBarToolStripMenuItem.Click
        Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
    End Sub

    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ArrangeIconsToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private m_ChildFormNumber As Integer

    Private Sub FileMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileMenu.Click

    End Sub

    Private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class



MODUL DATABASE

Imports System.Data
Imports System.Data.Sql

Module Koneksidatabase
    Public S1TI4AK As New OleDb.OleDbConnection
    'berfungsi untuk koneksi antar vb.net
    Public Tampil As New OleDb.OleDbCommand
    'berfungsi memberikan fasilitas untuk perintah2 query
    Public Tampil2 As New OleDb.OleDbCommand
    'berfungsi menyimpan data/hasil dari koneksi untuk sementara
    Public Tampilkan As OleDb.OleDbDataReader
    'berfungsi membuat variable untuk menampilakan sebuah data dalam grid
    Public Grid As New OleDb.OleDbDataAdapter
    Public Ds As New DataSet
    Public Table, hasilcek As String
    Public record As New BindingSource
    Public noo As Integer
    Public DMLSql As New OleDb.OleDbCommand
    Public Sub Koneksi()
        Try
            S1TI4AK.Close()
            'Server
            'Database.ConnectionString = "Provider=SQLOLEDB.1;Password=;Persist Security Info = True; User ID=sa; Initial Catalog=TI4K;Data Source=192.168.1.102"
            'Lokal
            S1TI4AK.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info = False; Initial Catalog=S1TI4AK;Data Source=;"
            S1TI4AK.Open()
        Catch ex As Exception
            MsgBox("Koneksi belum berhasil")
        End Try
        MsgBox("Koneksi berhasil")
    End Sub
End Module




Tidak ada komentar:

Posting Komentar