S
Scotty
I get stuck to write an update, insert and delete command, i am looking for
some help to start
Whats the best way to update 2 tables toe the database (Access)
below my code used to load my data.(2 tables)
Do someone has a good sample code to help me?
Many thanks in advance,
Marc.
'************begin code***************
Imports System
Imports System.Data
Imports system.Data.oledb
Public Class frmPostcodesTypedDS
Inherits System.Windows.Forms.Form
Dim strPath As String = "C:\AADatabases\BeActionData.mdb"
Dim strCnBeActionData As String = "provider=microsoft.jet.oledb.4.0;
Data Source=" & strPath
Dim daActionData As OleDbDataAdapter
'Dim mydtPostcodes As dtPostcodes = New dtPostcodes()
Dim cnBeActionData As New OleDbConnection(strCnBeActionData)
Dim dsLandenPostcodes As New DataSet
Dim da1 As New OleDbDataAdapter
Dim da2 As New OleDbDataAdapter
Dim dt1 As New DataTable
Dim dt2 As New DataTable
Private Sub frmPostcodes_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call LoadPostcodes()
End Sub
Sub LoadPostcodes()
' Dim dsLandenPostcodes As New DataSet
Dim dt1 As New DataTable
Dim dt2 As New DataTable
dsLandenPostcodes.Tables.Add(dt1)
dsLandenPostcodes.Tables.Add(dt2)
Dim da1 As New OleDbDataAdapter("Select * from [tblLanden]",
cnBeActionData)
Dim da2 As New OleDbDataAdapter("Select * from
[tblLandenPostcodes]", cnBeActionData)
da1.FillSchema(dt1, SchemaType.Mapped)
da2.FillSchema(dt2, SchemaType.Mapped)
Dim rel As New DataRelation("FKPostcLanden_Postcodes",
dsLandenPostcodes.Tables(0).Columns("Landcode"),
dsLandenPostcodes.Tables(1).Columns("Landcode"))
dsLandenPostcodes.Relations.Add(rel)
Dim bsPostcodeLanden As New BindingSource
bsPostcodeLanden.DataMember = dsLandenPostcodes.Tables(0).TableName
bsPostcodeLanden.DataSource = dsLandenPostcodes
Dim bsPostcodes As New BindingSource
bsPostcodes.DataSource = bsPostcodeLanden
bsPostcodes.DataMember = "FKPostcLanden_Postcodes"
da1.Fill(dt1)
da2.Fill(dt2)
Me.dgvPostcodeLanden.DataSource = bsPostcodeLanden
Me.dgvPostcodes.DataSource = bsPostcodes
End Sub
'************Einde code***************
some help to start
Whats the best way to update 2 tables toe the database (Access)
below my code used to load my data.(2 tables)
Do someone has a good sample code to help me?
Many thanks in advance,
Marc.
'************begin code***************
Imports System
Imports System.Data
Imports system.Data.oledb
Public Class frmPostcodesTypedDS
Inherits System.Windows.Forms.Form
Dim strPath As String = "C:\AADatabases\BeActionData.mdb"
Dim strCnBeActionData As String = "provider=microsoft.jet.oledb.4.0;
Data Source=" & strPath
Dim daActionData As OleDbDataAdapter
'Dim mydtPostcodes As dtPostcodes = New dtPostcodes()
Dim cnBeActionData As New OleDbConnection(strCnBeActionData)
Dim dsLandenPostcodes As New DataSet
Dim da1 As New OleDbDataAdapter
Dim da2 As New OleDbDataAdapter
Dim dt1 As New DataTable
Dim dt2 As New DataTable
Private Sub frmPostcodes_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call LoadPostcodes()
End Sub
Sub LoadPostcodes()
' Dim dsLandenPostcodes As New DataSet
Dim dt1 As New DataTable
Dim dt2 As New DataTable
dsLandenPostcodes.Tables.Add(dt1)
dsLandenPostcodes.Tables.Add(dt2)
Dim da1 As New OleDbDataAdapter("Select * from [tblLanden]",
cnBeActionData)
Dim da2 As New OleDbDataAdapter("Select * from
[tblLandenPostcodes]", cnBeActionData)
da1.FillSchema(dt1, SchemaType.Mapped)
da2.FillSchema(dt2, SchemaType.Mapped)
Dim rel As New DataRelation("FKPostcLanden_Postcodes",
dsLandenPostcodes.Tables(0).Columns("Landcode"),
dsLandenPostcodes.Tables(1).Columns("Landcode"))
dsLandenPostcodes.Relations.Add(rel)
Dim bsPostcodeLanden As New BindingSource
bsPostcodeLanden.DataMember = dsLandenPostcodes.Tables(0).TableName
bsPostcodeLanden.DataSource = dsLandenPostcodes
Dim bsPostcodes As New BindingSource
bsPostcodes.DataSource = bsPostcodeLanden
bsPostcodes.DataMember = "FKPostcLanden_Postcodes"
da1.Fill(dt1)
da2.Fill(dt2)
Me.dgvPostcodeLanden.DataSource = bsPostcodeLanden
Me.dgvPostcodes.DataSource = bsPostcodes
End Sub
'************Einde code***************