Вы находитесь на странице: 1из 4

Koding VB

Imports System.Data.OleDb
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Public Class Form1
Private connection As OleDbConnection
Private oleDbPenghubung As OleDbDataAdapter
Private ds As New DataSet()
Private cmd As New OleDbCommand
Private query As String = "Select Kode,Nama,Harga,Stok from Table1"
Private dr As OleDbDataReader
Private constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\$%$^KULIAH&&^%\projek\JADI BRAYYY\database.mdb"
Dim x As Integer = 0
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Try
Dim queryins As String = "Insert into Table1(Kode, Nama, Harga,
Stok) values('" & txtkode.Text & "','" & txtnama.Text & "'," & txtharga.Text &
"," & txtstok.Text & ")"
connection = New OleDbConnection(constring)
connection.Open()
cmd = New OleDbCommand(queryins, connection)
cmd.ExecuteNonQuery()
MessageBox.Show("Berhasil")
connection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
connection.Close()
End Try
txtkode.Clear()
txtnama.Clear()
txtstok.Clear()
txtharga.Clear()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
Private Sub txtkode_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtkode.LostFocus
Dim qrySel As String = "SELECT Nama,Harga,Stok FROM Table1 where Kode
= '" & txtkode.Text & "'"
Try

connection = New OleDbConnection(constring)


connection.Open()

If (txtkode.Text <> "") Then


cmd = New OleDbCommand(qrySel, connection)
dr = cmd.ExecuteReader()
dr.Read()
If (dr.HasRows = True) Then
txtnama.Text = dr.Item(0)
txtharga.Text = dr.Item(1)
txtstok.Text = dr.Item(2)
Else
MessageBox.Show("Kode Belum Dipakai !")
End If
End If
connection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
connection.Close()
End Try
End Sub

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


System.EventArgs) Handles Button1.Click
Dim queryupd As String = "update Table1 set Nama = '" & txtnama.Text &
"', Harga = " & Val(txtharga.Text) & ", Stok = " & Val(txtstok.Text) & " where
Kode ='" & txtkode.Text & "'"
Try
connection = New OleDbConnection(constring)
connection.Open()
cmd = New OleDbCommand(queryupd, connection)
cmd.ExecuteNonQuery()
connection.Close()
MessageBox.Show("berhasil gan")
Catch ex As Exception
MessageBox.Show(ex.Message)
connection.Close()
End Try
txtkode.Clear()
txtnama.Clear()
txtstok.Clear()
txtharga.Clear()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim querydel As String = "delete from Table1 where Kode = '" &
txtkode.Text & "'"
Try
connection = New OleDbConnection(constring)
connection.Open()
cmd = New OleDbCommand(querydel, connection)
cmd.ExecuteNonQuery()
MessageBox.Show("Berhasil")
connection.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
connection.Close()
End Try
txtkode.Clear()
txtnama.Clear()
txtstok.Clear()
txtharga.Clear()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Form2.Show()
Dim ds As New DataSet1
Dim t As DataTable = ds.Tables.Add("Items")
t.Columns.Add("Kode", Type.GetType("System.String"))
t.Columns.Add("Nama", Type.GetType("System.String"))
t.Columns.Add("Harga", Type.GetType("System.Int64"))
t.Columns.Add("Stok", Type.GetType("System.Int64"))
Dim
Dim
Dim
Dim

kode As String
nama As String
harga As Integer
stok As Integer

Dim r As DataRow
For counter As Integer = 0 To DataGridView1.RowCount - 2
kode = DataGridView1.Rows.Item(counter).Cells(0).Value
nama = DataGridView1.Rows.Item(counter).Cells(1).Value
harga = DataGridView1.Rows.Item(counter).Cells(2).Value
stok = DataGridView1.Rows.Item(counter).Cells(3).Value
r = t.NewRow()
r("Kode") = kode
r("Nama") = nama
r("Harga") = harga
r("Stok") = stok
t.Rows.Add(r)
Dim objRpt As New CrystalReport1
objRpt.SetDataSource(ds.Tables(1))
Form2.CrystalReportViewer1.ReportSource = objRpt
Form2.CrystalReportViewer1.Refresh()
Next

End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
DataGridView1.Rows.Add()
DataGridView1.Rows.Item(x).Cells(0).Value
DataGridView1.Rows.Item(x).Cells(1).Value
DataGridView1.Rows.Item(x).Cells(2).Value
DataGridView1.Rows.Item(x).Cells(3).Value
x = x + 1
End Sub
End Class

=
=
=
=

txtkode.Text
txtnama.Text
txtharga.Text
txtstok.Text

Вам также может понравиться