[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

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)

0
EGormly
Asked:
EGormly
  • 2
  • 2
1 Solution
 
jpaulinoCommented:
You can find some generic examples how to handle data, some using parameters:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23754631.html
For what you want you can use a OleDbCommand.ExecuteReader Method
http://msdn.microsoft.com/en-us/library/979byfca.aspx 
0
 
EGormlyAuthor Commented:
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
0
 
EGormlyAuthor Commented:
Excellent Link, I never came across that one. Perfectly fits my situation.
0
 
jpaulinoCommented:
Glad I could help!
jpaulino
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now