Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Imports System.Data
- Public Class Form6
- Dim Nama As String
- Dim Alamat As String
- Dim oledbKoneksi As OleDbConnection = New OleDbConnection
- Dim oledbPerintah As OleDbCommand = New OleDbCommand
- Dim lokasiFile As String = "D:\fileExcel\"
- Dim namaFile As String = "LatihanOLEDB2.xlsx"
- Dim stringKoneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & lokasiFile & namaFile & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
- Dim adapter As New OleDbDataAdapter
- Sub tampilIsiGrid()
- oledbKoneksi.ConnectionString = stringKoneksi
- oledbKoneksi.Open()
- oledbPerintah.Connection = oledbKoneksi
- oledbPerintah.CommandText = "SELECT * FROM [DataKaryawan$]"
- adapter.SelectCommand = oledbPerintah
- Dim ds As DataSet
- ds = New DataSet
- adapter.Fill(ds)
- DataGridView1.DataSource = ds.Tables(0)
- oledbKoneksi.Close()
- 'MsgBox("Done!")
- End Sub
- Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- 'oledbKoneksi.ConnectionString = stringKoneksi
- 'oledbKoneksi.Open()
- 'oledbPerintah.Connection = oledbKoneksi
- 'oledbPerintah.CommandText = "SELECT * FROM [DataKaryawan$]"
- 'adapter.SelectCommand = oledbPerintah
- 'Dim ds As DataSet
- 'ds = New DataSet
- 'adapter.Fill(ds)
- 'DataGridView1.DataSource = ds.Tables(0)
- 'MsgBox("Done!")
- Nama = TextBox1.Text
- Alamat = TextBox2.Text
- oledbKoneksi.ConnectionString = stringKoneksi
- oledbKoneksi.Open()
- oledbPerintah.Connection = oledbKoneksi
- oledbPerintah.CommandText = "INSERT INTO DataKaryawan(Nama, Alamat) values " & "('" & Nama & "', '" & Alamat & "')"
- oledbPerintah.ExecuteNonQuery()
- oledbKoneksi.Close()
- TextBox1.Text = ""
- TextBox2.Text = ""
- DataGridView1.Refresh()
- tampilIsiGrid()
- 'tampilIsiGrid()
- End Sub
- Private Sub Form6_Load(sender As Object, e As System.EventArgs) Handles Me.Load
- tampilIsiGrid()
- End Sub
- Private Sub DataGridView1_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
- Dim row As DataGridViewRow = DataGridView1.CurrentRow
- Me.TextBox1.Text = row.Cells(0).Value.ToString
- Me.TextBox2.Text = row.Cells(1).Value.ToString
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement