insert data ke datagridview

script buat insert data di datagridview..



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

System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the

'BappedaDataSet9.bappeda' table. You can move, or remove it, as needed.
Me.BappedaTableAdapter.Fill(Me.BappedaDataSet9.bappeda)
Me.OleDbDataAdapter1.Fill(dt)
Me.DataGridView1.DataSource = dt
End Sub

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

System.EventArgs) Handles Button1.Click
If TextBox2.TextLength = 0 Or TextBox3.TextLength = 0 Or

TextBox4.TextLength = 0 Then
MsgBox("Masih ada yang kosong, tolong dicek lagi!" )
Exit Sub
End If
Dim commandku As OleDb.OleDbCommand
Dim SQL As String
SQL = "Insert into bappeda values ( '" & TextBox2.Text & "',

'" & TextBox3.Text & "', '" & TextBox4.Text & "')"
commandku = New OleDb.OleDbCommand(SQL)
commandku.Connection = Me.OleDbConnection1
Me.OleDbConnection1.Open()
commandku.ExecuteNonQuery()
Me.OleDbConnection1.Close()
dt.Clear()
Me.OleDbDataAdapter1.Fill(dt)
Me.DataGridView1.DataSource = dt
MsgBox("Data sukses dimasukkan")
Catch ex As Exception
MsgBox(ex.Message)
Me.OleDbConnection1.Close()
End Try
End Sub

Komentar

Postingan populer dari blog ini

e-learning readiness