Datagridview添加/删除/修改/插入/保存数据库访问

时间:2016-06-24 15:23:05

标签: vb.net ms-access datagridview datagridviewcolumn

Imports System.Data.OleDb
Imports System.Data.DataTable


Public Class Form1
'Change "C:\Users\Jimmy\Documents\Merchandise.accdb" to your database location
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\test.accdb"
Dim MyConn As OleDbConnection
Dim cmd As New OleDb.OleDbCommand
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim tables As DataTableCollection
Dim source1 As New BindingSource
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'ce code du load data marche nickel , c une alternative au boutton load
    Me.Table1TableAdapter.Fill(Me.TestDataSet.Table1)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'load data 
    MyConn = New OleDbConnection
    MyConn.ConnectionString = connString
    ds = New DataSet
    tables = ds.Tables
    da = New OleDbDataAdapter("Select * from [Table1]", MyConn) 'Change items to your database name
    da.Fill(ds, "TestDataSet.Table1") 'Change items to your database name
    Dim view As New DataView(tables(0))
    source1.DataSource = view
    DataGridView1.DataSource = view
    'fin
End Sub



End Class

我想添加fontions(从(Textbox1.Text / 2/3)插入行/删除行/修改行/保存更改到数据库) 让我们打电话给每个bouton做一个动作(bouton 1/2/3/4)

enter image description here

0 个答案:

没有答案