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

Imports System.Data.

SqlClient

Partial Class EntryMhs


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)"
sql = sql & " VALUES('" & tbNim.Text & "','" & tbNama.Text & "','" &
ddProdi.Text & "')"

Dim cmd As SqlCommand = New SqlCommand(sql, cn)


Dim jmlrec As Integer = cmd.ExecuteNonQuery
If jmlrec > 0 Then
Response.Write("Input Data Mahasiswa Berhasil")
Else
Response.Write("Input Data Mahasiswa Gagal")
End If
Catch ex As Exception
Response.Write("Ada Kesalahan koneksi Database ! ")
Finally
cn.Close()
End Try
End Sub
End Class

You might also like