SQL Server

class koneksi

Public Class koneksi
Private Conn As OleDb.OleDbConnection = Nothing
Public Function konek() As OleDb.OleDbConnection
Dim ConnString As String
ConnString = "provider=SQLOLEDB.1;integrated security=sspi;persist scurity info=false; " + _
" initial catalog=DbRawatjalan;data source=."
Try
Conn = New OleDb.OleDbConnection(ConnString)
Conn.Open()

Catch ex As Exception
MessageBox.Show("Koneksi Erros: " + ex.Message)
End
End Try
Return Conn
End Function

End Class

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

modul

Imports System.Data.OleDb
Imports System.Data


Module myModule
Public DTraeder As OleDb.OleDbDataReader
Public DTadapter As OleDb.OleDbDataAdapter
Public DTtable As New DataTable
Public sql As String
Public conn As New OleDb.OleDbConnection
Public CMD As New OleDb.OleDbCommand


End Module

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

coding form

Public Class Form1
Dim conn As New koneksi

Sub isicombo()
ComboBox1.Items.Add("Teknik Informatika")
ComboBox1.Items.Add("Teknik Komputer")
ComboBox1.Items.Add("Teknik Akuntansi")
ComboBox1.Items.Add("Manajemen Informatika")

End Sub


Sub bersih()
TextBox1.Clear()
TextBox2.Clear()
ComboBox1.Text = "Select"
TextBox4.Clear()
TextBox1.Focus()

End Sub

Sub simpan()
'memeriksa apakah kode nota dalam table pembayaran apakah sudah ada..
sql = "SELECT*FROM dbo.mahasiswa where nim='" & Trim(TextBox1.Text) & "'"
Try
CMD = New OleDb.OleDbCommand(sql, conn.konek)
DTraeder = CMD.ExecuteReader()
If DTraeder.HasRows Then
MessageBox.Show("Nim Mahasiswa sudah ada ")
DTraeder.Close()
conn.konek.Close()
Exit Sub
Else
DTraeder.Close()

End If
'Menyimpan data kedalam table pesanan
Try
sql = "insert into dbo.Mahasiswa(nim,nama,jurusan,alamat)" & _
"values('" & Me.TextBox1.Text & "'," & _
"'" & Me.TextBox2.Text & "'," & _
"'" & Me.ComboBox1.Text & "'," & _
"'" & Me.TextBox4.Text & "')"
CMD = New OleDb.OleDbCommand(sql, conn.konek)
CMD.ExecuteNonQuery()
Call bersih()

Catch ex As Exception
MessageBox.Show("Data gagal disimpan ", ex.Message)

End Try
Catch ex As Exception
End Try

End Sub

Sub caridata()
'method untuk mengisi textbok nama pelanggan ambil data dari table pelanggan
sql = "SELECT * from mahasiswa where nim ='" & TextBox1.Text.Trim & "'"
DTtable = New DataTable
CMD = New OleDb.OleDbCommand(sql, conn.konek)
DTraeder = CMD.ExecuteReader()
If DTraeder.HasRows = True Then
DTraeder.Read()
TextBox2.Text = DTraeder("nama")
ComboBox1.Text = DTraeder("jurusan")
TextBox4.Text = DTraeder("alamat")
DTtable.Clear()
'menampilkan data hasil pencarian kedalam datagrid
DTtable = New DataTable
DTadapter = New OleDb.OleDbDataAdapter(sql, conn.konek)
DTadapter.Fill(DTtable)
With Me.DataGridView1
.DataSource = DTtable
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.AllowUserToAddRows = False
End With
DTtable.Dispose()
DTadapter.Dispose()
conn.konek.Close()
Else
MessageBox.Show("Data tidak ditemukan periksa NIM mahasiswa")
Call bersih()
End If
DTraeder.Close()
End Sub
Sub tampilData()
sql = " Select * From mahasiswa order by nim asc"
DTtable.Clear()
DTtable = New DataTable
DTadapter = New OleDb.OleDbDataAdapter(sql, conn.konek)
DTadapter.Fill(DTtable)
With Me.DataGridView1
.DataSource = DTtable
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.AllowUserToAddRows = False
End With
DTtable.Dispose()
DTadapter.Dispose()
conn.konek.Close()
End Sub
Sub hapusdata()
sql = " delete From mahasiswa where nim ='" & Trim(TextBox1.Text) & "'"
If MessageBox.Show("Yakin akan menghapus record ini??", "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Try
CMD = New OleDb.OleDbCommand(sql, conn.konek)
CMD.ExecuteNonQuery()
Call bersih()
Catch ex As Exception
MessageBox.Show("Data gagal dihapus")
End Try
End If
End Sub
Sub Perbaikandata()
sql = "update mahasiswa set nim ='" & Trim(TextBox1.Text) & "'," & _
"nama='" & Trim(Me.TextBox2.Text) & "'," & _
"jurusan='" & Trim(Me.ComboBox1.Text) & "' ," & _
"alamat='" & Trim(Me.TextBox4.Text) & "'" & _
"where nim='" & Trim(Me.TextBox1.Text) & "'"
If MessageBox.Show("record ini akan di perbaiki??", "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Try
CMD = New OleDb.OleDbCommand(sql, conn.konek)
CMD.ExecuteNonQuery()
Call bersih()

Catch ex As Exception
MessageBox.Show("Data gagal diperbaiki", ex.Message)
End Try
End If

End Sub
Sub tampilkeform()
Me.TextBox1.Text = Me.DataGridView1.SelectedCells(0).Value
Me.TextBox2.Text = Me.DataGridView1.SelectedCells(1).Value
Me.ComboBox1.Text = Me.DataGridView1.SelectedCells(2).Value
Me.TextBox4.Text = Me.DataGridView1.SelectedCells(3).Value
End Sub



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Text = "Select"
Call isicombo()
Call tampilData()


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call caridata()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call simpan()
Call tampilData()
End Sub

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

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Call hapusdata()
Call tampilData()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Call Perbaikandata()
Call tampilData()
End Sub


Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
Call tampilkeform()

End Sub
End Class

0 komentar:

Posting Komentar

Post komentar kritik dan saran anda disini ya...

◄ Newer Post Older Post ►
 

Copyright 2012 Serba Gratis Seo Elite by BLog BamZ | Blogger Templates