Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need help using VB.NET to retrieve ACCESS data.

Posted on 2004-10-21
1
Medium Priority
?
226 Views
Last Modified: 2010-04-23
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 =). )

Thanks

M
0
Comment
Question by:dunnieboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
ID: 12373017
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)

       Try
           '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
       Me.CreateDS()
       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
   Listbox1.Items.Add(dr.Item("Field1").ToString)
Next
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question