Monday, 30 November 2015

Cara Update data di Datagridview dengan edit rows vb.net

setelah kemaren udah nulis bagaimana cara menampilkan data di datagridview dari database kali ini saya mau share cara update data di datagridview dengan edit rows. jadi kaya sql server setiap kita edit rows otomatis data nya akan berubah di database

berikut codingan nya.

Imports System.Data.SqlClient

Public Class Form2

    Const connectionstring As String = "Data Source=TOP;Initial Catalog=latihan;Persist Security Info=True;User ID=atm; password=atm"
    Private SQL As String = "select * from siswa"
    Private con As New SqlConnection(connectionstring)
    Private dt As New DataTable
    Private adapter As New SqlDataAdapter(Sql, con)
    Private commandbuilder As New SqlCommandBuilder(adapter)

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        adapter.Fill(dt)
        DataGridView1.DataSource = dt
    End Sub


    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        adapter.Update(dt)
    End Sub

    Private Sub DataGridView1_RowLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowLeave
        adapter.Update(dt)
    End Sub



End Class


sekian cara update data di Datagridview dengan edit rows di vbnet. silahkan download project nya di sini http://www.mediafire.com/download/cw025fdq0hinp2e/Datagridview+update+edit+rows.rar


Perhatian: Yuk Baca Artikel bagus di Nurul Musthofa

Artikel Terkait

1 comment:

  1. ERROR KANG

    {"Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information."}


    ReplyDelete

 

Network

Pesan

Semoga situs ini bermanfaat