5
MODULE TAMBAHAN VB .NET 2008 Disusun Oleh : WAN H.M. ==================================================================================================== Public Class Form3 Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click If (LCase(txtuser.Text) = LCase("wan") And txtpass.Text = "123") _ Or (LCase(txtuser.Text) = LCase("iwan") And txtpass.Text = "456") Then Form1.Show() Me.Hide() Else MessageBox.Show("Invalid password, please try again", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Information) txtuser.Text = "" txtpass.Text = "" txtuser.Focus() End If End Sub End Class

MODULE TAMBAHAN VB conn - zebaoth filekoneksi ke database' ... 'Dim index As Integer 'membuat variable bertipe integer' 'Dim mode As String Dim commandquery As String Dim insertquery

Embed Size (px)

Citation preview

MODULE TAMBAHAN VB .NET 2008 Disusun Oleh : WAN H.M.

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

Public Class Form3

Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click

If (LCase(txtuser.Text) = LCase("wan") And txtpass.Text = "123") _

Or (LCase(txtuser.Text) = LCase("iwan") And txtpass.Text = "456") Then

Form1.Show() Me.Hide() Else

MessageBox.Show("Invalid password, please try again", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Information)

txtuser.Text = ""

txtpass.Text = "" txtuser.Focus()

End If

End Sub

End Class

LISTING PROGRAM

Public Class Form1

Private Sub Btnsave_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click

'Dim connect As OleDb.OleDbConnection 'mendeklarasikan variable untuk

koneksi ke database' 'Dim damhs As OleDb.OleDbDataAdapter 'mendeklarasikan variable untuk

menampung data' 'Dim dsmhs As New DataSet 'Dim index As Integer 'membuat variable bertipe integer'

'Dim mode As String Dim commandquery As String

Dim insertquery As New OleDb.OleDbCommand

Dim con As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated

Security=SSPI;Persist Security Info=False;Initial Catalog=STTI;Data

Source=.")

commandquery = "insert into Mhs values('" & Txtnim.Text & "','" & Txtnama.Text & "','" & TxtSemester.Text & "')"

Try con.Open()

insertquery.Connection = con

insertquery.CommandText = commandquery insertquery.ExecuteNonQuery()

MsgBox("Data Telah Disimpan ", MsgBoxStyle.OkOnly, "Informasi")

con.Close()

Catch ex As Exception

MsgBox("Data telah gagal dalam penyimpanan data, mohon diulangi.

=P", MsgBoxStyle.OkOnly, "Informasi")

MessageBox.Show(ex.Message)

End Try Txtnim.Text = "" Txtnama.Text = ""

TxtSemester.Text = ""

End Sub

Private Sub BtnRefresh_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles BtnRefresh.Click

Dim con As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=STTI;Data

Source=.")

Dim cmdStudent As New OleDb.OleDbCommand Dim daStudent As New OleDb.OleDbDataAdapter

Dim dsStudent As New DataSet

Txtnim.Text = ""

Txtnama.Text = "" TxtSemester.Text = ""

Try cmdStudent = con.CreateCommand

cmdStudent.CommandText = "SELECT * FROM Mhs"

daStudent.SelectCommand = cmdStudent

daStudent.Fill(dsStudent, "Mhs")

dg1.DataSource = dsStudent

dg1.DataMember = "Mhs"

dg1.ReadOnly = True

Catch ex As Exception

MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")

End Try End Sub

Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click

Dim con As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated

Security=SSPI;Persist Security Info=False;Initial Catalog=STTI;Data

Source=.") Dim cmdStudent As New OleDb.OleDbCommand

Dim daStudent As New OleDb.OleDbDataAdapter

Dim dsStudent As New DataSet

Dim index As String

If Txtnama.Text <> "" Then

If MsgBox("Anda Yakin Ingin Menghapus Pasien Dengan Nama : " & Txtnama.Text & " ?", MsgBoxStyle.OkCancel, "Konfirmasi Penghapusan") = MsgBoxResult.Cancel Then

' do nothing

Else

Try

con.Open()

cmdStudent = con.CreateCommand cmdStudent.CommandText = "DELETE FROM Mhs WHERE nama ='"

& Trim(Txtnama.Text) & "'"

index = cmdStudent.ExecuteReader.RecordsAffected If index > 0 Then

MsgBox("Mahasiswa Dengan Nama " & Trim(Txtnama.Text)

& " Berhasil Dihapus", MsgBoxStyle.OkOnly, "Info Hapus Mahasiswa") Else

MsgBox("Mahasiswa Dengan Nama " & Trim(Txtnama.Text) & " Gagal Dihapus", MsgBoxStyle.OkOnly, "Info Hapus Mahasiswa")

End If

con.Close()

Catch ex As Exception

MsgBox("Error: " & ex.Source & ": " & ex.Message,

MsgBoxStyle.OkOnly, "Connection Error !!")

End Try End If

Else

MsgBox("Isi Nama Mahasiswa Yang Ingin Dihapus!!",

MsgBoxStyle.OkOnly, "Info Data")

End If

End Sub

Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles BtnExit.Click Me.Close()

End Sub

End Class

Report