Minggu, 06 Januari 2013

Koneksi sql server ke vb


=> Buatlah tabel pada sql server


















=> Masukkan data pada table












=> Masuk ke vb
Buka database "klik menu Data > Add New Data Source… > Database
kemudian Next > Dataset, lalu Next > New Connection… > pilih Microsoft SQL
Server, lalu Continue















































=> Drag semua data ke form, kemudian menambahkan beberapa button dan sebuah textbox





































=> Masukkan codingnya 


Public Class Form1

    Private Sub MhsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.MhsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbmhsDataSet)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbmhsDataSet.mhs' table. You can move, or remove it, as needed.
        Me.MhsTableAdapter.Fill(Me.DbmhsDataSet.mhs)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.MhsBindingSource.MoveFirst()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.MhsBindingSource.MovePrevious()
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.MhsBindingSource.MoveNext()
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Me.MhsBindingSource.MoveLast()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If (MhsBindingSource.Find("NIM", TextBox1.Text)) > -1 Then
            MsgBox("Data berhasil ditemukan")
        Else
            MsgBox("Data tidak berhasil ditemukan")
        End If

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim Mencari As String
        Mencari = InputBox("Masukkan Jurusan Yang Di Cari", "Filter ...")
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Me.MhsBindingSource.AddNew()
        NIMTextBox.Focus()
        TtlDateTimePicker.ResetText()
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Me.Validate()
        Me.MhsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbmhsDataSet)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If MsgBox("Apakah Anda Yakin ?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete") = vbYes Then
            Me.MhsBindingSource.RemoveCurrent()
        End If

    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If MsgBox("Apakah anda ingin keluar ?", vbYesNo + vbQuestion + vbDefaultButton2, "Keluar") = vbYes Then
            Me.Close()
        End If
    End Sub
End Class


=> Dan Hasilnya seperti dibawah ini :



Read More...