DataTableMapping.ColumnMappings.Add : DataTableMapping « System.Data « VB.Net by API






DataTableMapping.ColumnMappings.Add

  

Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Data.OleDb
Imports System.Data.Common
Imports System.Data


Public Class MainClass
    
    Shared Sub Main()
        Dim dsUsers As New DataSet("Users")

        Try
            Dim dbConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source=Employee.mdb")
            Dim daUsers As New OleDbDataAdapter("SELECT ID, FirstName, LastName FROM Employee", dbConn)
            Dim dcmUserID As New DataColumnMapping("ID", "EmployeeID")
            Dim dcmFirstName As New DataColumnMapping("FirstName", "FirstName")
            Dim dcmLastName As New DataColumnMapping("LastName", "LastName")
            Dim dtmUsers As New DataTableMapping("Table", "Employee")
            dtmUsers.ColumnMappings.Add(dcmUserID)
            dtmUsers.ColumnMappings.Add(dcmFirstName)
            dtmUsers.ColumnMappings.Add(dcmLastName)

            daUsers.TableMappings.Add(dtmUsers)
            daUsers.Fill(dsUsers)

            Dim cb As New OleDbCommandBuilder(daUsers)

            Dim r As DataRow = dsUsers.Tables(0).NewRow()
            r("FirstName") = "Eddie"
            r("LastName") = "Robinson"
            dsUsers.Tables(0).Rows.Add(r)

            daUsers.Update(dsUsers.GetChanges())

            dsUsers.AcceptChanges()
        Catch ex As Exception
            dsUsers.RejectChanges()
            Console.WriteLine(ex.Message)
        End Try
    End Sub
End Class



   
    
  








Related examples in the same category

1.New DataTableMapping