1 / 12

Penyimpanan data ke database melalui store procedure

Nyimas Artina , S.Kom , M.Si. Penyimpanan data ke database melalui store procedure . DESAIN LAYOUT FORM UTAMA DAN FORM PEGAWAI.

peggy
Download Presentation

Penyimpanan data ke database melalui store procedure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NyimasArtina, S.Kom, M.Si Penyimpanan data ke database melalui store procedure

  2. DESAIN LAYOUT FORM UTAMA DAN FORM PEGAWAI Aktifkan Form Utama (FrmUtama) dantambahkansatubuahMenuStripdansatubuahStatusStripkedalamFrmUtama. TambahkanToolStripMenuItemdengancaraklik MenuStrip1 danketikkan “&File” padatulisan “Type Here”. Lakukanhal yang samadisebelahnyadanketikkan “&Data Entry”. Dan tambahkanToolStripMenuItemdibawahFileToolStripMenuItemdengannama “&Exit”. TambahkanjugaToolStripMenuItemdibawahDataEntryToolStripMenuItemdengannama “Data &Pegawai”. Untuklebihjelasnyalihatgambar. Selanjutnyakitaatur StatusStrip1. Klik StatusStrip1 dantambahkanToolStripStatusLabelsebanyak 3 buahdengancaraklikAddToolStripStatusLabel►StatusLabel. Untuklebihjelasnyalihatgambar.

  3. Aturnilaipropertidarisetiapkontrol yang adadiFrmUtamasebagaiberikut :

  4. Sehingga tampilannya menjadi seperti gambar di bawah ini : KemudianaktifkanFrmPegawaidantambahkan 2 buahGroupBoxdan 1 buahDataGridView. Tambahkan 6 buah Label, 5 buahTextBox, dan 1 buahDateTimePickerkedalam GroupBox1. Tambahkanjuga 11 buah Button kedalam GroupBox2.

  5. Aturpropertidan layout kontrol-kontroltersebutsepertidibawahini :

  6. SOURCE CODE FORM UTAMA DAN FORM PEGAWAI • AktifkanFrmUtamadan double klikpada Form sehinggaandadibawake Code Editor untukmenangani Event Form_Load, ketikkankode program berikut : • ToolStripStatusLabel1.Text = "Ready . . ." • ToolStripStatusLabel2.Text = "Username : " & Username • ToolStripStatusLabel3.Text = Today.Date.ToLongDateString • Kodeiniberfungsiuntukmengaturnilai Text/ tulisan yang munculdiToolStripStatus. • Kemudian double klikpada Menu Exit (ExitToolStripMenuItem) danketikkankode program berikutini : • Msg = MessageBox.Show("Yakin TutupAplikasiIni?", "Konfirmasi", _ • MessageBoxButtons.YesNo, MessageBoxIcon.Question) • If Msg = vbYes Then • End • Else • Exit Sub • End If • Menampilkankotakpesankonfirmasi yang menanyakanapakahaplikasiakanditutup. Jikajawabannya Yes makaaplikasiakanditutuptapijikatidakmakaakankeluardariSubrutin. • Double klikpada Menu DataPegawai (ExitToolStripMenuItem) danketikkankode program berikutini : • FrmPegawai.Parent = Me • FrmPegawai.ShowDialog() • Mengatur Parent (Form Induk) dariFrmPegawaiyaitu Me(FrmUtama). KemudianmenampilkanFrmPegawai.

  7. Sebelummenambahkan source code keFrmPegawai, andatambahkanterlebihdahulusebuah Class di Folder AksesDatadanberinama “ManipulasiData.vb”. Class iniberfungsiuntukmemanipulasi (insert, update dan delete) data Pegawai. Jadiketikaandainginmenambah, merubahataumenghapus data yang adadi Table Pegawai, cukupmemanggilsalahsatu method yang adadi Class ManipulasiDataini. Untukmenambahkan method pada Class ManipulasiData, ketikkan source code berikutinidi Class ManipulasiData : • Imports System.Data • Imports System.Data.SqlClient • Namespace AksesData • Public Class ManipulasiData • Public Function TambahData(ByVal nip As String, ByValnama As String, _ • ByValtgllahir As Date, ByValjalan As String, ByValkota As String, _ • ByValkodepos As String) As SqlCommand • Dim koneksiku As New AksesData.KoneksiDatabase • Command = New SqlCommand("SPI_PEGAWAI", koneksiku.Buka) • Command.CommandType = CommandType.StoredProcedure • Dim PRM1 As New SqlParameter("@NIP", SqlDbType.VarChar, 10) • PRM1.Value = nip • Dim PRM2 As New SqlParameter("@NAMA", SqlDbType.VarChar, 25) • PRM2.Value = nama • Dim PRM3 As New SqlParameter("@TGLLAHIR", SqlDbType.DateTime) • PRM3.Value = tgllahir • Dim PRM4 As New SqlParameter("@JALAN", SqlDbType.VarChar, 30) • PRM4.Value = jalan

  8. Dim PRM5 As New SqlParameter("@KOTA", SqlDbType.VarChar, 20) • PRM5.Value = kota • Dim PRM6 As New SqlParameter("@KODEPOS", SqlDbType.VarChar, 5) • PRM6.Value = kodepos • With Command.Parameters • .Add(PRM1) • .Add(PRM2) • .Add(PRM3) • .Add(PRM4) • .Add(PRM5) • .Add(PRM6) • End With • Command.ExecuteNonQuery() • Dim hasil As New SqlCommand("", koneksiku.Tutup) • Return hasil • End Function • Public Function UbahData(ByVal nip As String, ByValnama As String, _ • ByValtgllahir As Date, ByValjalan As String, ByValkota As String, _ • ByValkodepos As String) As SqlCommand • Dim koneksiku As New AksesData.KoneksiDatabase • Command = New SqlCommand("SPU_PEGAWAI", koneksiku.Buka) • Command.CommandType = CommandType.StoredProcedure

  9. Dim PRM1 As New SqlParameter("@NIP", SqlDbType.VarChar, 10) PRM1.Value = nip Dim PRM2 As New SqlParameter("@NAMA", SqlDbType.VarChar, 25) PRM2.Value = nama Dim PRM3 As New SqlParameter("@TGLLAHIR", SqlDbType.DateTime) PRM3.Value = tgllahir Dim PRM4 As New SqlParameter("@JALAN", SqlDbType.VarChar, 30) PRM4.Value = jalan Dim PRM5 As New SqlParameter("@KOTA", SqlDbType.VarChar, 20) PRM5.Value = kota Dim PRM6 As New SqlParameter("@KODEPOS", SqlDbType.VarChar, 5) PRM6.Value = kodepos With Command.Parameters .Add(PRM1) .Add(PRM2) .Add(PRM3) .Add(PRM4) .Add(PRM5) .Add(PRM6) End With Command.ExecuteNonQuery() Dim hasil As New SqlCommand("", koneksiku.Tutup) Return hasil End Function

  10. Public Function HapusData(ByVal nip As String) As SqlCommand Dim koneksiku As New AksesData.KoneksiDatabase Command = New SqlCommand("SPD_PEGAWAI", koneksiku.Buka) Command.CommandType = CommandType.StoredProcedure Dim PRM1 As New SqlParameter("@NIP", SqlDbType.VarChar, 10) PRM1.Value = nip Command.Parameters.Add(PRM1) Command.ExecuteNonQuery() Dim hasil As New SqlCommand("", koneksiku.Tutup) Return hasil End Function End Class End Namespace

More Related