Advertisement
Guest User

FrmEditmahasiswa.aspx

a guest
Jul 17th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 3.82 KB | None | 0 0
  1. Imports System.Data.OleDb
  2. Imports System.Data
  3. Imports System.Data.SqlClient
  4. Imports System.IO
  5. Imports System.Net
  6.  
  7. Public Class FrmEditmahasiswa
  8.     Inherits System.Web.UI.Page
  9.  
  10.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  11.  
  12.         TxtNIM.Enabled = False
  13.  
  14.         If Not IsPostBack Then
  15.             Dim PNim As String
  16.             If Session("BrowseMahNIM") = "" Or Session("BrowseMahNIM") = Nothing Then
  17.                 PNim = ""
  18.             Else
  19.                 PNim = Session("BrowseMahNIM")
  20.             End If
  21.             Dim conn As SqlConnection
  22.             Dim cmd As SqlCommand
  23.             Dim rd As SqlDataReader
  24.  
  25.             Dim strconn As String = "Data Source=DESKTOP-K7FC1E9;Initial Catalog=DB_ASPNET;Persist Security Info=True;User ID=sa; Password=12345678"
  26.  
  27.             conn = New SqlConnection(strconn)
  28.             conn.Open()
  29.  
  30.             cmd = New SqlCommand("select * from mahasiswa where nim= '" & PNim & "'", conn)
  31.  
  32.             rd = cmd.ExecuteReader
  33.             rd.Read()
  34.  
  35.             If rd.HasRows = 0 Or rd.HasRows = Nothing Then
  36.             Else
  37.                 If rd("nim") Is DBNull.Value Or rd("nim") = "" Then
  38.                     TxtNIM.Text = ""
  39.                 Else
  40.                     TxtNIM.Text = rd("nim")
  41.                 End If
  42.  
  43.                 If rd("nama") Is DBNull.Value Or rd("nama") = "" Then
  44.                     TxtNama.Text = ""
  45.                 Else
  46.                     TxtNama.Text = rd("nama")
  47.                 End If
  48.  
  49.                 If rd("alamat") Is DBNull.Value Then
  50.                     TxtAlamat.Text = ""
  51.                 Else
  52.                     TxtAlamat.Text = rd("alamat")
  53.                 End If
  54.  
  55.  
  56.  
  57.                 If rd("tanggallahir") Is DBNull.Value Then
  58.                     TxtTanggalLahir.Text = ""
  59.                 Else
  60.  
  61.                     TxtTanggalLahir.Text = Format(rd("tanggallahir"), "dd/MM/yyyy")
  62.  
  63.                 End If
  64.  
  65.                 If TxtTanggalLahir.Text = "" Then
  66.                 Else
  67.                     If TxtTanggalLahir.Text = "01/01/1900" Then
  68.                         TxtTanggalLahir.Text = ""
  69.                     Else
  70.                         Dim TL1 As Date
  71.                         Dim TLF1 As String
  72.                         TxtTanggalLahir.Text = rd("tanggallahir")
  73.                         TL1 = TxtTanggalLahir.Text
  74.                         TLF1 = TL1.ToString("yyyy/MM/dd")
  75.                         TxtTanggalLahir.Text = TLF1
  76.                     End If
  77.                 End If
  78.             End If
  79.         End If
  80.     End Sub
  81.  
  82.     Protected Sub BtnCariData_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnCariData.Click
  83.         Response.Redirect("FrmBrowseMahasiswaCookies.aspx")
  84.     End Sub
  85.  
  86.     Protected Sub BtnEdit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnEdit.Click
  87.         update("UPDATE mahasiswa SET nama = '" & TxtNama.Text & "', alamat = '" & TxtAlamat.Text & "', tanggallahir= '" & TxtTanggalLahir.Text & "' where nim = '" & TxtNIM.Text & "' ")
  88.  
  89.         TxtNama.Text = ""
  90.         TxtAlamat.Text = ""
  91.         TxtTanggalLahir.Text = ""
  92.  
  93.         Dim sMsg As String = " Data Sudah Di Ubah ... !!!"
  94.  
  95.         ScriptManager.RegisterStartupScript(Page, Page.GetType, Guid.NewGuid().ToString(), "alert('" & sMsg & "')", True)
  96.     End Sub
  97.  
  98.     Protected Sub Delete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Delete.Click
  99.         deletes("delete from mahasiswa where nim = '" & TxtNIM.Text & "'")
  100.  
  101.         TxtNIM.Text = ""
  102.         TxtNama.Text = ""
  103.         TxtAlamat.Text = ""
  104.         TxtTanggalLahir.Text = ""
  105.  
  106.         Dim sMsg As String = " Data Sudah Di Hapus ... !!!"
  107.  
  108.         ScriptManager.RegisterStartupScript(Page, Page.GetType, Guid.NewGuid().ToString(), "alert('" & sMsg & "')", True)
  109.     End Sub
  110. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement