2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Imports System.Data.

SqlClient

Partial Class inputmhs


Inherits System.Web.UI.Page

Dim cn As SqlConnection = Nothing


Dim cnsql As String =
ConfigurationManager.ConnectionStrings("cnsql").ConnectionString

Protected Sub btSimpan_Click(sender As Object, e As EventArgs) Handles


btSimpan.Click
cn = New SqlConnection(cnsql)
Try
cn.Open()
Dim sql As String = "INSERT INTO Mahasiswa(NIM, Nama, Prodi) VALUES('"
& tbNim.Text & "','" & tbNama.Text & "','" & tbProdi.Text & "')"
Dim cmd As SqlCommand = New SqlCommand(sql, cn)
If cmd.ExecuteNonQuery > 0 Then
Response.Write("Proses Simpan Data Berhasil")
Else
Response.Write("Proses Simpan Data Gagal")
End If

Catch ex As Exception
Response.Write("Koneksi Gagal")
Exit Sub
Finally
cn.Close()
cn = Nothing
End Try

End Sub
End Class

You might also like