Need help using VB.NET to retrieve ACCESS data.

I am a complete newbie to VB.NET programming. All I am trying to do is retrieve all the data from an ACCESS database and then loop through it to store it in an array.

Maybe I dont need to store it in an array. The concepts of datasets are strange to me. How do I access specific records in the datasets. I have a book on the subject, but it is only using bound controls (the datagrid). I don't want to use the bound controls at all.

I have set up my database connection(OleDbConnection1) and data adapter(OleDbAdapter1). I also have a dataset ("Blinds_Dataset").  The table is very simple. an ID (key) column, and two data columns.

This is so frustrating compared to the old way of SQL into recordsets or arrays.  ((its been 10 years since I wrote even one line of code =). )


Who is Participating?
iboutchkineConnect With a Mentor Commented:
Imports System.Data.OleDb

Public Class Form1
   Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region
   Dim fsConn As String = _
  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Data Source=C:\TestDB\TestDB.mdb;"

   Dim ds As DataSet
   Dim da As OleDbDataAdapter
   Dim fsSQL As String = "SELECT * FROM Test"
   Dim fsSource As String = "Test"

   Private Sub CreateDS()
       ds = New DataSet()
       'Connect to database and specify sSQL
       da = New OleDbDataAdapter(fsSQL, fsConn)

           'using DataAdapter enter records from table to DataSet
           da.Fill(ds, fsSource) 'fsSource is a table
       Catch objExc As System.Exception
           'do something
           Exit Sub
       End Try
   End Sub

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       dg.DataSource = ds.Tables("Test")
        dg.DataMember = "Test"
   End Sub

End Class

now you have all the records in the datatable  Test

you can read these records like that

Dim dr As DataRow

For Each dr In Ds.Tables("Test").Rows
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.