Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'接続情報
Dim cn As New OleDbConnection
'接続情報
cn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;" _
& "data source=Order.mdb"
'DataAdapterの作成
Dim da As OleDbDataAdapter
da = New OleDbDataAdapter("select * from goods", cn)
'データを取得
Dim ds As New DataSet
da.Fill(ds, "goods")
'DataGridViewに表示
DataGridView1.DataSource = ds.Tables("goods")
End Sub
データベースに追加して更新
例
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'接続情報
Dim cn As New OleDbConnection
'接続情報
cn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;" _
& "data source=Order.mdb"
'DataAdapterの作成
Dim da As OleDbDataAdapter
da = New OleDbDataAdapter("select * from goods", cn)
'データを取得
Dim ds As New DataSet
da.Fill(ds, "goods")
'値を変更
ds.Tables("Goods").Rows(0)("GoodsName") = "つやつや"
'更新用コマンドを作成
Dim cmdbuilder As New OleDbCommandBuilder
cmdbuilder.DataAdapter = da
'更新
da.Update(ds, "Goods")
MessageBox.Show("更新しました")
End Sub
0 件のコメント:
コメントを投稿