473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Access database usage question

I am an old VB6 programmer, and we have recently gone to VB.NET. I am struggling to duplicate some of the things I had done in VB5 and VB6 to the new language.

What I need to do is to use VB.NET code to :

#1: Open an MS Access database
#2: Retrieve the data from one of the tables into an array
#3: Once I have the array filled, I can process the data in the array via VB.NET code

If my DB is ddddd and my table within the DB is ttttt, what code do I need to open the database and read each member from the table sequentially until the end of the table?

Thanks for answering.

Nov 21 '05 #1
3 1426
A connection, a datareader, and an array. Here's an example using a combo,
but you could do the same with an array:

Dim strSelect as String = "SELECT ...."

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
DB.Name & ";"
Dim connDB As OleDbConnection = New OleDbConnection(strConn)

Dim cmd As New OleDbCommand(strSelect, connDB)
Dim dr As OleDbDataReader

connDB.Open()
dr = cmd.ExecuteReader()

While (dr.Read())
Dim strResult As String
If Not dr.IsDBNull(0) Then strResult = dr.GetString(0)
If strResult <> "" Then
cmbResults.Items.Add(strResult)
End If
End While

dr.Close()

connDB.Close()

Me.Close()

"Terry Maguire" <te*******@verizon.net> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
I am an old VB6 programmer, and we have recently gone to VB.NET. I am
struggling to duplicate some of the things I had done in VB5 and VB6 to the
new language.

What I need to do is to use VB.NET code to :

#1: Open an MS Access database
#2: Retrieve the data from one of the tables into an array
#3: Once I have the array filled, I can process the data in the array via
VB.NET code

If my DB is ddddd and my table within the DB is ttttt, what code do I need
to open the database and read each member from the table sequentially until
the end of the table?

Thanks for answering.
Nov 21 '05 #2
Hi Terry,

I'd recommend using a dataset/datatable and you can then disregard an array, as you can read through the dataset (it is, essentially, an array of data in memory, and modifiable back to the backend, if you so choose). For this you should use an oledb data adapter. You can use the connection string that Earl displayed, but you'll need to set the selectcommand of the data adapter and then use the fill method. Take a look at google or msdn for some of the fairly easy details of this. Here's a simple example (where a connection object has already been established):
Dim datblarchives As New OleDbDataAdapter("select * from tblarchives where id = " & Chr(39) & glformidnum & Chr(39), OleDbConnection1)

Dim dstblarchives As New DataSet("tblarchives")

datblarchives.Fill(dstblarchives, "tblarchives")

HTH,

Bernie Yaeger

"Terry Maguire" <te*******@verizon.net> wrote in message news:uW**************@tk2msftngp13.phx.gbl...
I am an old VB6 programmer, and we have recently gone to VB.NET. I am struggling to duplicate some of the things I had done in VB5 and VB6 to the new language.

What I need to do is to use VB.NET code to :

#1: Open an MS Access database
#2: Retrieve the data from one of the tables into an array
#3: Once I have the array filled, I can process the data in the array via VB.NET code

If my DB is ddddd and my table within the DB is ttttt, what code do I need to open the database and read each member from the table sequentially until the end of the table?

Thanks for answering.

Nov 21 '05 #3
Terry,

In addition to Earl and Bennie.

A Dataset is an object that holds datatables. You can compare Datatables
with recordset, although the major difference is that datasets/datatables
are disconnected and a recordset stays connected to the database.

To go through a datatable as with a movenext from a recordset can be.

dim mytable as datatable = ds.tables(0) ' you can do it with the dataset
direct as well
dim mydatarow as datarow1 = mydatatable.rows(0) ' which is the first row it
it extist
did mydatarow as datarow2 = mydatatable.rows(1) ' which is the second row if
it exist

(In a lot of cases is the currencymanager used, that has nothing to do with
money however with the current position in the datatable)

Both the datareader and datasets are good to use.

When you use it in connection with a "data" control as the datatagrid,
combobox, and listbox or with a "single item" control as the textbox,
checkbox, label or whatever, than the dataset/datatable is in my opinion
the best choise.

When you use it with a control as a treeview or a listview that has to be
loaded in advance, the datareader is in my opinion a better choise.

I hope this gives some more ideas?

Cor

"Terry Maguire" te*******@verizon.net

I am an old VB6 programmer, and we have recently gone to VB.NET. I am
struggling to duplicate some of the things I had done in VB5 and VB6 to the
new language.

What I need to do is to use VB.NET code to :

#1: Open an MS Access database
#2: Retrieve the data from one of the tables into an array
#3: Once I have the array filled, I can process the data in the array via
VB.NET code

If my DB is ddddd and my table within the DB is ttttt, what code do I need
to open the database and read each member from the table sequentially until
the end of the table?

Thanks for answering.
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jo | last post by:
Hello I am a web designer who is slowly trying to learn more about web development. I have a client who would like to drive their website using a database so I am now in the perfect situation...
8
by: Frnak McKenney | last post by:
Back when computer dinosaurs roamed the earth and the precursors to today's Internet were tiny flocks of TDMs living symbiotically with the silicon giants, tracking access to data processing...
35
by: deko | last post by:
Do I get more scalability if I split my database? The way I calculate things now, I'll be lucky to get 100,000 records in my Access 2003 mdb. Here some math: Max mdb/mde size = 2000 x 1024 =...
7
by: Ruben Baumann | last post by:
Just wondered if anyone has had occasion to use, or does use, FileMaker, or Raining Data's Omnis, or Alpha5's software, and how they compare with Access? Ruben
12
by: Paul H | last post by:
Say I have a Windows 2000 server running Terminal Services with a single file Access DB (not front end/back end) on it, could multiple users access the data base simultaneously? Paul
13
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't...
3
by: DwC | last post by:
Hi, We have a ms access database that we will be using to develop a website which would have fairly low usage levels. We have some experience with windows apps but not so much with asp.net...
32
by: vonclausowitz | last post by:
Hi All, I have database with names on which I want to use the soundex option. So I have created two seperate fields for the Lastname and Firstname in which I save the Soundex version of a new...
6
by: pippapippa | last post by:
I should be most grateful for a little advice. I have used Access 2000 & latterly 2002. Am about to upgrade since it is evident that documentation, tutorials etc are more readily available in...
21
by: nihad.nasim | last post by:
Hi there, I have a database in Access that I need on the web. The web page should connect to the database and write records for certain tables and view records for others. I want to know a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.