Link to home
Start Free TrialLog in
Avatar of EGormly
EGormlyFlag for United States of America

asked on

Simple selecting records from access table

Visual Studio 2008
Visual basic.net

I am having a very hard time understanding .net vs VB6 or vbscript in terms of selecting records from an access database.

Normally all I need to do is this:

ConStringLoginSQL = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydatabase.mdb"
Set objConn = Server.CreateObject("ADODB.Connection")       
objConn.ConnectionString = ConStringLoginSQL
objConn.Open
Set objRS = Server.CreateObject("ADODB.Recordset")      
strSQL = "SELECT * FROM TableName"      
Set objRS= objConn.execute(strSQL)      

      While not objRS.eof

            MyVariable = objRS("MyField")

      objRS.movenext
      wend

objRS.close
set objRS=nothing
objConn.close
set objConn=nothing

That allows me to manipulate, store or do whatever with the data individually as I am looping through the records.

With .Net all I can find examples of are loading data in to "datashapes" and "grids" all at once.
I dont understand.. how am I supposed to manipulate data this way?
I do not need to show the data only compare and make calculations and such.

what am I missing here?

Can someone show me how to do it the "old way" with .net
(note, it's Visual studio 2008, not 2003 or 2005)

ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EGormly

ASKER

This worked perfectly...

    Using connection As New OleDbConnection(connectionString)
        Dim command As New OleDbCommand(queryString, connection)

        connection.Open()

        Dim reader As OleDbDataReader = command.ExecuteReader()
        While reader.Read()
            Console.WriteLine(reader(0).ToString())
        End While
        reader.Close()
    End Using


thanks for the link and the OleDbCommand.ExecuteReader Method
Avatar of EGormly

ASKER

Excellent Link, I never came across that one. Perfectly fits my situation.
Glad I could help!
jpaulino