0% found this document useful (0 votes)
20 views

Windowsapplication1: 'Perintah Koneksi Database Disimpan 1 Baris

This code defines a class for connecting to a SQL database and performing CRUD operations. It establishes a connection to a SQL database, defines commands to insert and select data from two tables, and includes event handler methods for buttons to save, cancel, add new data, find data, delete data, and close the application. Data is bound to two data grids for display.

Uploaded by

Auranda Qolfi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Windowsapplication1: 'Perintah Koneksi Database Disimpan 1 Baris

This code defines a class for connecting to a SQL database and performing CRUD operations. It establishes a connection to a SQL database, defines commands to insert and select data from two tables, and includes event handler methods for buttons to save, cancel, add new data, find data, delete data, and close the application. Data is bound to two data grids for display.

Uploaded by

Auranda Qolfi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Imports System.

Data
Imports System.Data.SqlClient

Public Class WindowsApplication1


Public koneksi As String
Public sql1, sql2 As String
Public conn As SqlClient.SqlConnection = Nothing
Public cmd As SqlClient.SqlCommand = Nothing
Public dtadapter As New SqlClient.SqlDataAdapter
Public dttable As New DataTable

Private Sub WindowsApplication1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
'PERINTAH KONEKSI DATABASE DISIMPAN 1 BARIS
koneksi = "Data Source=ACER;Initial Catalog=fahlefi;Integrated Security=True"
conn = New SqlClient.SqlConnection(koneksi)
conn.Open()
End Sub
Sub simpan()
'PERINTAH sql1 DISIMPAN 1 BARIS
sql1 = "Insert into Table_1 values('" & Me.TextBox1.Text & "','" &
Me.TextBox2.Text & "','" & Me.TextBox3.Text & "','" & Me.TextBox4.Text & "')"
cmd = New SqlClient.SqlCommand(sql1)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub
Sub REZAGEGEH()
sql1 = "select * from dbo.Table_1"
dtadapter = New SqlDataAdapter(sql1, conn)
Dim gegeh As New DataTable
gegeh.Clear()
dtadapter.Fill(gegeh)
DataGridView1.DataSource = gegeh
End Sub
Sub simpan2()
'PERINTAH sql1 DISIMPAN 1 BARIS
sql2 = "Insert into Table_2 values('" & Me.TextBox1.Text & "','" &
Me.TextBox5.Text & "')"
cmd = New SqlClient.SqlCommand(sql2)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub
Sub REZAGEGEHBANGET()
sql2 = "select * from dbo.Table_2"
dtadapter = New SqlDataAdapter(sql2, conn)
Dim gegehbanget As New DataTable
gegehbanget.Clear()
dtadapter.Fill(gegehbanget)
DataGridView2.DataSource = gegehbanget
End Sub

Private Sub btsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
simpan()
REZAGEGEH()
simpan2()
REZAGEGEHBANGET()
MsgBox("Data Sudah Disimpan", MsgBoxStyle.Information,
"Perhatian")
End Sub

Private Sub btcancel_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click

MsgBox("Data Sudah Dibatalkan", MsgBoxStyle.Information, "Perhatian")

End Sub

Private Sub btnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click

MsgBox("Data Baru", MsgBoxStyle.Information, "Perhatian")

End Sub

Private Sub btFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button4.Click

End Sub

Private Sub btDelete_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click

MsgBox("Data Telah Dihapus", MsgBoxStyle.Information, "Perhatian")

End Sub

Private Sub btclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button6.Click
Me.Close()

End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As


System.EventArgs)

End Sub
End Class

You might also like