Koneksi Database
Tugas 6 : Database
Cara pembuatan dan penjelasan program
sebelum kita membuat program kita buat database terlebih
dahulu dengan menggunakan Sql server 2005, meskipun banyak sekali bahasa
pemrograman yang bisa digunakan untuk membuat database antara lain microsoff
acces ,mysql dan lain-lain.
·
Langkah pertama
buat database menggunakan Sql sever 2005
Buka sql server 2005 – connect – klik kanan database - pilih new database – database name –
sesuaikan tempat penyimpanan – klik oc -
isi – pilih primary key - save.
·
Langkah kedua koneksi visual basic dengan database
Buka visual basic – klik file new project - pilih vb –
windows form aplication – isikan name dan location penyimpanan – klik
ok.
Pilih
data – add new source – database – dataset –
next – new connectiont –pilih change(isi sesuai bahasa pemrograman yang digunakan untuk
membuat database) - isikan servername (.) – isikan use windows/ use sql server pada log on to the server - test connectiont – ok – yes – checklist table
– finish.
·
Langkah ketiga masukan toolbox
Pilih
data – show data source – drag ke form - masukan program.
Koding
program
Public Class Form1
Private Sub TbmahasiswaBindingNavigatorSaveItem_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
Handles
TbmahasiswaBindingNavigatorSaveItem.Click
Me.Validate()
Me.TbmahasiswaBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DbmahasiswaDataSet)
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 'DbmahasiswaDataSet.tbmahasiswa' table. You
can move, or remove it, as needed.
Me.TbmahasiswaTableAdapter.Fill(Me.DbmahasiswaDataSet.tbmahasiswa)
End Sub
Private Sub Button1_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button1.Click
Me.TbmahasiswaBindingSource.MoveFirst()
End Sub
‘Pesan Keluar Saat Mengklik Tombol Next Akhir’
Private Sub Button2_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button2.Click
Dim max
As Integer = Me.TbmahasiswaBindingSource.Count
Dim skr
As Integer = Me.TbmahasiswaBindingSource.Position
If skr <
max - 1 Then
Me.TbmahasiswaBindingSource.MoveNext()
Else :
MsgBox("Data sudah akhir")
End If
End Sub
Private Sub Button4_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button4.Click
Me.TbmahasiswaBindingSource.MoveLast()
End Sub
‘Pesan Keluar Saat Mengklik Tombol Previous Akhir’
Private Sub Button3_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button3.Click
Dim max
As Integer = Me.TbmahasiswaBindingSource.Count
Dim skr
As Integer = Me.TbmahasiswaBindingSource.Position
If skr
<> 0 Then
Me.TbmahasiswaBindingSource.MovePrevious()
Else :
MsgBox("Data sudah akhir")
End If
End Sub
Private Sub Button5_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button5.Click
Me.TbmahasiswaBindingSource.AddNew()
End Sub
Private Sub Button6_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button6.Click
Me.Validate()
Me.TbmahasiswaBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DbmahasiswaDataSet)
End Sub
Private Sub Button7_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button7.Click
Me.TbmahasiswaBindingSource.RemoveCurrent()
End Sub
Private Sub Button8_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button8.Click
If
MsgBox("Apakah anda ingin keluar",
4 + +32 + +256, "Keluar") = vbYes Then Me.Close()
End Sub
Private Sub PrintToolStripButton_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
End Sub
‘Pesan Keluar Saat Mengklik tombol cari’
Private Sub Button9_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button9.Click
If
(TbmahasiswaBindingSource.Find("nama",
TextBox1.Text)) > -1 Then
MsgBox("Data
di temukan ")
Else
MsgBox("Data
yang anda cari tidak tersedia")
End If
End Sub
Private Sub Button10_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button10.Click
TextBox1.Text = " "
End Sub
Private Sub Button11_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button11.Click
Me.TbmahasiswaBindingSource.Filter
= "nama='" & TextBox1.Text
& " '"
End Sub
End Class