Perancangan Database Dengan SQL Server Dan ASP.NET
Bismillah, saya ingin berbagi hasil perancangan database dengan SQL Server dan ASP.NET, sebelumnya saya ingin berterimakasih untuk teman-teman saya yang telah membantu saya menyempurnakan aplikasi ini.
Aplikasi ini di buat untuk memenuhi tugas matakuliah Perancangan Basis Data. Berikut langsung saja saya bagikan tampilan juga source code dibawah ini:
1) Buatlah Database baru pada SQL Server, kemudian buatlah tabel berikut
2) Setelah itu buatlah projek website baru pada Visual Studio 2012, kemudian desain tampilan dengan menambahkan Label, Text Field, Button dan Grid View seperti berikut
3) Gambar diatas Grid View telah di koneksikan dengan SQL Server, Bagaimana caranya? berikut penjelasannya
>> Pilih Configure Data Source >> New Connection >> (Data Source) pilih change, pilih Microsoft SQL Server >> Masukan Server Name (sesuai nama koneksi server pada SQL Server) >> Pilih database name, masukan database yang telah dibuat di SQL Server >> kemudian Next sampai Finish
4) Setelah tampilan menjadi seperti diatas, Mari lihat source code berikut agar aplikasi dapat berjalan
Imports System.Data.OleDb
Imports System.Data.SqlClient
Module Module1
Public sqlCon As New SqlConnection
Public Sub dbConn()
Dim server As String
server = "Data Source=DESKTOP-5PR8DHF\MYSQLSERVER;Initial Catalog=pendaftaran;Integrated Security=True"
sqlCon = New SqlConnection(server)
sqlCon.Open()
End Sub
End Module
Inherits System.Web.UI.Page
Dim sql As String
Dim sda As SqlDataAdapter
Dim ds As DataSet
Dim dt As DataTable
Dim sreader As SqlDataReader
Sub tampil_data()
clear()
dbConn()
sql = "Select * From tabel_siswa"
Dim da = New SqlDataAdapter(sql, sqlCon)
Dim ds = New Data.DataSet
ds.Reset()
da.Fill(ds)
GridView1.DataSource = ds.Tables(0)
End Sub
txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txt4.Text = ""
txt5.Text = ""
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
dbConn()
Dim query As New SqlCommand("Insert into tabel_siswa values('" & txt1.Text & "','" & txt2.Text & "','" & txt3.Text & "','" & txt4.Text & "','" & txt5.Text & "')", sqlCon)
Dim z = query.ExecuteNonQuery()
If z = 1 Then
MsgBox("Data Berhasil Disimpan", MsgBoxStyle.Information, "Sukses")
tampil_data()
Else
MsgBox("Data Gagal Disimpan", MsgBoxStyle.Information, "Gagal")
End If
sqlCon.Close()
Response.Redirect("pendaftaran.aspx")
End Sub
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim query As New SqlCommand("Delete into tabel_siswa values('" & txt1.Text & "','" & txt2.Text & "', '" & txt3.Text & "', '" & txt4.Text & "','" & txt5.Text & "')", sqlCon)
Dim z = query.ExecuteNonQuery()
If z = 1 Then
MsgBox("Data Berhasil Dihapus", MsgBoxStyle.Information, "Sukses")
tampil_data()
Else
MsgBox("Data Gagal Dihapus", MsgBoxStyle.Information, "Gagal")
End If
sqlCon.Close()
Response.Redirect("pendaftaran.aspx")
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim query As New SqlCommand("Update into tabel_siswa values('" & txt1.Text & "','" & txt2.Text & "','" & txt3.Text & "','" & txt4.Text & "','" & txt5.Text & "')", sqlCon)
Dim z = query.ExecuteNonQuery()
If z = 1 Then
MsgBox("Data Berhasil Diupdate", MsgBoxStyle.Information, "Sukses")
tampil_data()
Else
MsgBox("Data Gagal Diupdate", MsgBoxStyle.Information, "Gagal")
End If
sqlCon.Close()
Response.Redirect("Pendaftaran.aspx")
End Sub
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
clear()
End Sub
End Class
5) Setelah itu, running dengan browser yang tersedia hingga muncul hasil running seperti berikut untuk tombol Insert
Aplikasi ini di buat untuk memenuhi tugas matakuliah Perancangan Basis Data. Berikut langsung saja saya bagikan tampilan juga source code dibawah ini:
1) Buatlah Database baru pada SQL Server, kemudian buatlah tabel berikut
2) Setelah itu buatlah projek website baru pada Visual Studio 2012, kemudian desain tampilan dengan menambahkan Label, Text Field, Button dan Grid View seperti berikut
3) Gambar diatas Grid View telah di koneksikan dengan SQL Server, Bagaimana caranya? berikut penjelasannya
>> Pilih Configure Data Source >> New Connection >> (Data Source) pilih change, pilih Microsoft SQL Server >> Masukan Server Name (sesuai nama koneksi server pada SQL Server) >> Pilih database name, masukan database yang telah dibuat di SQL Server >> kemudian Next sampai Finish
4) Setelah tampilan menjadi seperti diatas, Mari lihat source code berikut agar aplikasi dapat berjalan
Import Data dan Beri Module SQL Connection
Imports System.DataImports System.Data.OleDb
Imports System.Data.SqlClient
Module Module1
Public sqlCon As New SqlConnection
Public Sub dbConn()
Dim server As String
server = "Data Source=DESKTOP-5PR8DHF\MYSQLSERVER;Initial Catalog=pendaftaran;Integrated Security=True"
sqlCon = New SqlConnection(server)
sqlCon.Open()
End Sub
End Module
Beri variable dan Set Data
Partial Class pendaftaranInherits System.Web.UI.Page
Dim sql As String
Dim sda As SqlDataAdapter
Dim ds As DataSet
Dim dt As DataTable
Dim sreader As SqlDataReader
Sub tampil_data()
clear()
dbConn()
sql = "Select * From tabel_siswa"
Dim da = New SqlDataAdapter(sql, sqlCon)
Dim ds = New Data.DataSet
ds.Reset()
da.Fill(ds)
GridView1.DataSource = ds.Tables(0)
End Sub
Untuk Mengahapus Text Field
Sub clear()txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txt4.Text = ""
txt5.Text = ""
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Tombol Insert
dbConn()
Dim query As New SqlCommand("Insert into tabel_siswa values('" & txt1.Text & "','" & txt2.Text & "','" & txt3.Text & "','" & txt4.Text & "','" & txt5.Text & "')", sqlCon)
Dim z = query.ExecuteNonQuery()
If z = 1 Then
MsgBox("Data Berhasil Disimpan", MsgBoxStyle.Information, "Sukses")
tampil_data()
Else
MsgBox("Data Gagal Disimpan", MsgBoxStyle.Information, "Gagal")
End If
sqlCon.Close()
Response.Redirect("pendaftaran.aspx")
End Sub
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
Tombol Delete
Dim query As New SqlCommand("Delete into tabel_siswa values('" & txt1.Text & "','" & txt2.Text & "', '" & txt3.Text & "', '" & txt4.Text & "','" & txt5.Text & "')", sqlCon)
Dim z = query.ExecuteNonQuery()
If z = 1 Then
MsgBox("Data Berhasil Dihapus", MsgBoxStyle.Information, "Sukses")
tampil_data()
Else
MsgBox("Data Gagal Dihapus", MsgBoxStyle.Information, "Gagal")
End If
sqlCon.Close()
Response.Redirect("pendaftaran.aspx")
End Sub
Tombol Update
Dim query As New SqlCommand("Update into tabel_siswa values('" & txt1.Text & "','" & txt2.Text & "','" & txt3.Text & "','" & txt4.Text & "','" & txt5.Text & "')", sqlCon)
Dim z = query.ExecuteNonQuery()
If z = 1 Then
MsgBox("Data Berhasil Diupdate", MsgBoxStyle.Information, "Sukses")
tampil_data()
Else
MsgBox("Data Gagal Diupdate", MsgBoxStyle.Information, "Gagal")
End If
sqlCon.Close()
Response.Redirect("Pendaftaran.aspx")
End Sub
Tombol Refresh
clear()
End Sub
End Class
5) Setelah itu, running dengan browser yang tersedia hingga muncul hasil running seperti berikut untuk tombol Insert
Baiklah ini hasilnya, semoga bermanfaat... Terimakasih...
Komentar
Posting Komentar