Tahap2nya adalah :
1. Membuat databases di Sql Server 2005.
create database ican
use ican
create table cln_mhs
(
no_daftar char(6) not null,
tgl_daftar datetime,
nama_cln varchar (50),
tmp_lhr_cln varchar (50),
tgl_lhr_cln datetime,
jkel char (2),
agm_cln varchar(20),
email_cln varchar(100),
hp_cln varchar(12),
tlp_cln varchar(10),
almt_cln varchar(100),
asal_sklh_cln varchar(50)
)
alter table cln_mhs
add constraint pkcln primary key (no_daftar)
Select*From cln_mhs
VB.Net 2005
Buat Class Conection :
Imports System.Data
Imports System.Data.Sql
Module modul_koneksi
Public database As New OleDb.OleDbConnection
Public tampil2 As New OleDb.OleDbCommand
Public tampilkan As OleDb.OleDbDataReader
Public hasilcek As String
Public Sub bukakoneksi()
database.Close()
Try
database.ConnectionString = "provider=sqloledb.1;integrated security=SSPI;persist security info=false; initial catalog=indra;data source=."
database.Open()
MessageBox.Show("Koneksi kedatabase berhasil")
Catch ex As Exception
MessageBox.Show("koneksi gagal")
End
End Try
End Sub
End Module
Buat Form :
Public Class menu_tahu
Sub celrecord()
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select * from tahu where kode_th='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then
hasilcek = True
Else
hasilcek = False
End If
End Sub
Sub bersihkan()
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call simpan()
End Sub
Sub simpan()
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
Call celrecord()
Try
If hasilcek = "False" Then
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Insert into tahu (kode_th,jenis_th,harga_th,stock_th)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
tampil2.ExecuteNonQuery()
Call bersihkan()
Else
MsgBox("Data sudah ada , silahkan cek data yang akan diinput ", MsgBoxStyle.Critical, "Input data") ''critical = ! dalam msgbox
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim res As DialogResult
res = MessageBox.Show("Yakin Ingin Keluar ?", "Confirm Dialog", MessageBoxButtons.OKCancel)
If res = DialogResult.OK Then
Me.Close()
Else
Call bersihkan()
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Call bersihkan()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call ubah()
End Sub
Sub ubah()
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Update tahu set jenis_th='" & TextBox2.Text & "', harga_th='" & TextBox3.Text & "', stock_th='" & TextBox4.Text & "'where kode_th='" & TextBox1.Text & "'"
tampil2.ExecuteNonQuery()
Call bersihkan()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call hapus()
End Sub
Sub hapus()
If TextBox1.Text = "" Then Exit Sub
If TextBox2.Text = "" Then Exit Sub
If TextBox3.Text = "" Then Exit Sub
If TextBox4.Text = "" Then Exit Sub
Try
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Delete from tahu where kode_th='" & Trim(TextBox1.Text) & "'"
tampil2.ExecuteNonQuery()
Call bersihkan()
TextBox1.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Call cari()
End Sub
Sub cari()
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " select* from tahu where kode_th='" & Trim(TextBox5.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then
While tampilkan.Read()
If (IsDBNull(tampilkan("kode_th"))) Then
Else
TextBox1.Text = tampilkan("kode_th")
TextBox2.Text = tampilkan("jenis_th")
TextBox3.Text = tampilkan("harga_th")
TextBox4.Text = tampilkan("stock_th")
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End Sub
Private Sub menu_tahu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'IndraDataSet.tahu' table. You can move, or remove it, as needed.
Me.TahuTableAdapter.Fill(Me.IndraDataSet.tahu)
End Sub
End Class
Okey lah Tutorial dari saya smoga bermanfaat,,,!! key,,,!! Good Luck,, jangan lupa perbanyak minum ... :)
salam to anak2 KP.Corporation. ( Icank KP )
-----------------------------------------------------------------------------------------
sekedar tambahan >>>>
Imports System.Data
Imports System.Data.Sql
Module koneksi_database
Public database As New OleDb.OleDbConnection
Public tampil2 As New OleDb.OleDbCommand
Public tampilkan As OleDb.OleDbDataReader
Public hasilcek As String
Public Sub bukakoneksi()
database.Close()
Try
database.ConnectionString = "provider=sqloledb.1;integrated security=SSPI;persist security info=false; initial catalog=ican;data source=."
database.Open()
MessageBox.Show("Koneksi kedatabase berhasil")
Catch ex As Exception
MessageBox.Show("Koneksi gagal")
End
End Try
End Sub
End Module
Source yang ada di Form >>>>>>>>>>
Public Class Form2
Sub cekrecord()
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = "select *from pmb where no_daftar='" & Trim(TextBox1.Text) & "'"
tampilkan = tampil2.ExecuteReader
If tampilkan.HasRows = True Then
hasilcek = True
Else
hasilcek = False
End If
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'IcankDataSet1.pmb' table. You can move, or remove it, as needed.
Me.PmbTableAdapter.Fill(Me.IcankDataSet1.pmb)
'TODO: This line of code loads data into the 'IcankDataSet.mhs' table. You can move, or remove it, as needed.
Me.MhsTableAdapter.Fill(Me.IcankDataSet.mhs)
'TODO: This line of code loads data into the 'IcankDataSet1.pmb' table. You can move, or remove it, as needed.
Me.PmbTableAdapter.Fill(Me.IcankDataSet1.pmb)
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call bersih()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim res As DialogResult
res = MessageBox.Show("You Really To exit", "Confirm Dialog", MessageBoxButtons.OKCancel)
If res = DialogResult.OK Then
Me.Close()
Else
Call bersih()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call nyimpan()
End Sub
Sub nyimpan()
If TextBox1.Text = "" Then Exit Sub ''then exit sub = keluar dari sub class dgan syarat textbox harus diisi/pengecekan validasi
Call cekrecord()
Try
If hasilcek = "False" Then
Call bukakoneksi()
tampil2.Connection = database
tampil2.CommandType = CommandType.Text
tampil2.CommandText = " Insert into pmb (no_daftar,nama_mhs,jlh_byr,tgl_byr) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text& "')"
tampil2.ExecuteNonQuery()
Call bersih()
Else
MsgBox("Data sudah ada , silahkan cek data yang akan diinput ", MsgBoxStyle.Critical, "Input data") ''critical = ! dalam msgbox
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
End Class
................................................................................................................................
okey,,,, thxs..!! salam cuy,,!!!