View Single Post
Old March 20th, 2006, 05:12 PM
Bob Bedell Bob Bedell is offline
Friend of Wrox
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts

If you wanted to assign a field value from an Access table to a base data type variable (like Doulbe) stored in a DataView, you might to something like the following in VB.NET (see third to last line of code for variable assignment). This is just a console app:

Sub Main()

        ' Open a connection to Access.
        Dim cnn As OleDbConnection
        Dim connectionString As String = _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\JetBackendDB.mdb;" & _
            "User ID=Admin;" & _
        cnn = New OleDb.OleDbConnection(connectionString)

        ' Create DataTable
        Dim ds As New DataSet
        With ds.Tables.Add("tblRecords")
            .Columns.Add("ID", GetType(Integer))
            .Columns.Add("DoubleField", GetType(Double))
        End With

        ' Load DataTable
        Dim cmd As New OleDbCommand
        cmd = New OleDbCommand("SELECT * FROM tblRecords", cnn)

        Dim rdr As OleDbDataReader = cmd.ExecuteReader()
        Dim row As DataRow
        Do While rdr.Read()
            row = ds.Tables("tblRecords").NewRow()
            row("ID") = rdr("ID")
            row("DoubleField") = rdr("DoubleField")

        ' Create DataView
        Dim vue As New DataView(ds.Tables("tblRecords"))

        ' Assign value in a DataView row to a Double variable.
        Dim vueRow As DataRowView = vue(0)
        Dim dblDoubleField As Double = vueRow("DoubleField")

    End Sub