View Single Post
  #4 (permalink)  
Old March 20th, 2006, 06:02 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
Default

Here's are better (more concise) version of the same, just 'cause I got way to much time on my hands:

VB.NET
Code:
Imports System.Data.OleDb

Module App

    Sub Main()
        Dim strCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\JetBackendDB.mdb;" & _
            "User ID=Admin;Password="
        Dim strSQL As String = "SELECT * FROM tblRecords"

        Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSQL, strCnn)
        Dim ds = New DataSet
        da.Fill(ds, "tblRecords")

        Dim dv = New DataView(ds.Tables(0))

        ' Assign value in a DataView row to a Double variable.
        Dim dvRow As DataRowView = dv(0)
        Dim dblDoubleField As Double = dvRow("DoubleField")
        Console.WriteLine(dblDoubleField)
        Console.Read()
    End Sub

End Module
C#
Code:
using System;
using System.Data;
using System.Data.OleDb;

class App {
    static void Main() {

        // Open a connection to Access.
        String strCnn = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
            @"Data Source=C:\JetBackendDB.mdb;" +
            "User ID=Admin;Password=";
        String strSQL = "SELECT * FROM tblRecords";

        OleDbDataAdapter da = new OleDbDataAdapter(strSQL, strCnn);
        DataSet ds = new DataSet();
        da.Fill(ds, "tblRecords");

        DataView dv = new DataView(ds.Tables[0]);

        // Assign value in a DataView row to a Double variable.
        DataRowView dvRow = dv[0];
        Double dblDoubleField = (Double)dvRow["DoubleField"];
        Console.WriteLine(dblDoubleField);
        Console.Read();
    }
}
HTH,

Bob

Reply With Quote