0% found this document useful (0 votes)
9 views2 pages

KJHH

The document contains code for a form that connects to a SQL database and performs CRUD operations on two tables - DataCustomer and DataJual. It defines methods to refresh two datagridviews by executing queries to select data from each table. It also includes methods to insert new records into each table by executing insert queries, and update existing records by executing update queries. The form loads and calls the refresh methods to populate the datagridviews.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

KJHH

The document contains code for a form that connects to a SQL database and performs CRUD operations on two tables - DataCustomer and DataJual. It defines methods to refresh two datagridviews by executing queries to select data from each table. It also includes methods to insert new records into each table by executing insert queries, and update existing records by executing update queries. The form loads and calls the refresh methods to populate the datagridviews.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Imports System.Data.

SqlClient
Public Class Form1
Dim Conn As New SqlConnection
Dim Sconn As New SqlConnection
Dim cmd As SqlCommand
Dim SQLAdp As New SqlDataAdapter
Dim SQL As String

Private Sub RefreshGrid()


Dim DS As New DataSet
Dim DT As New DataTable

Sconn = New SqlConnection(My.Settings.SCONN)


If Sconn.State = ConnectionState.Closed Then Sconn.Open()
SQL = "select * from DataCustomer"
SQLAdp = New SqlDataAdapter(SQL, Sconn)
SQLAdp.Fill(DS)
For Each DT In DS.Tables
DataGridView1.DataSource = DT
Next
End Sub

Private Sub RefreshGrid1()


Dim DS As New DataSet
Dim DT As New DataTable

Sconn = New SqlConnection(My.Settings.SCONN)


If Sconn.State = ConnectionState.Closed Then Sconn.Open()
SQL = "select * from DataJual"
SQLAdp = New SqlDataAdapter(SQL, Sconn)
SQLAdp.Fill(DS)
For Each DT In DS.Tables
DataGridView2.DataSource = DT
Next
End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles


btnSave.Click
Dim save As String
Sconn = New SqlConnection(My.Settings.SCONN)
If Sconn.State = ConnectionState.Closed Then Sconn.Open()
save = "insert into DataCustomer values " &
"('" & Trim(txtKodeCustomer.Text) & "', " &
"'" & Trim(txtNamaCustomer.Text) & "', " &
"'" & Trim(txtNoTelp.Text) & "')"
cmd = New SqlCommand(save, Sconn)
cmd.ExecuteNonQuery()
MsgBox("Data telah bertambah", MsgBoxStyle.Information, "INSERT DATA")
Sconn.Close()
Call RefreshGrid()

Dim saveJual As String


Sconn = New SqlConnection(My.Settings.SCONN)
If Sconn.State = ConnectionState.Closed Then Sconn.Open()
saveJual = "insert into DataJual values " &
"('" & Trim(txtNoFaktur.Text) & "', " &
"'" & Trim(txtKodeCustomer.Text) & "', " &
"'" & Trim(txtTotalPenjualan.Text) & "')"
cmd = New SqlCommand(saveJual, Sconn)
cmd.ExecuteNonQuery()
MsgBox("Data telah bertambah", MsgBoxStyle.Information, "INSERT DATA")
Sconn.Close()
Call RefreshGrid1()
End Sub

Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles


btnUpdate.Click
Dim Perbaiki As String
Sconn = New SqlConnection(My.Settings.SCONN)
If Sconn.State = ConnectionState.Closed Then Sconn.Open()
Perbaiki = "Update DataCustomer set KODE = '" & Trim(txtKodeCustomer.Text)
& "', NAMA = '" & Trim(txtNamaCustomer.Text) & "', NOTELP = '" &
Trim(txtNoTelp.Text) & "'"
cmd = New SqlCommand(Perbaiki, Sconn)
cmd.ExecuteNonQuery()
MsgBox("Data telah diperbaiki", MsgBoxStyle.Information, "UPDATE DATA")
Sconn.Close()
Call RefreshGrid()

Dim Perbaiki As String


Sconn = New SqlConnection(My.Settings.SCONN)
If Sconn.State = ConnectionState.Closed Then Sconn.Open()
Perbaiki = "Update DataJual set NOFAKTUR = '" & Trim(txtNoFaktur.Text) &
"', CODECUST = '" & Trim(txtKodeCustomer.Text) & "', TOTAL = '" &
Trim(txtTotalPenjualan.Text) & "'"
cmd = New SqlCommand(Perbaiki, Sconn)
cmd.ExecuteNonQuery()
MsgBox("Data telah diperbaiki", MsgBoxStyle.Information, "UPDATE DATA")
Sconn.Close()
Call RefreshGrid()
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Call RefreshGrid()
Call RefreshGrid1()
End Sub
End Class

You might also like