Solved

VB.Net: data structures

Posted on 2009-07-08
6
1,017 Views
Last Modified: 2013-12-25
Hi,

I just started programming in VB.Net and I'm doing some research on available data structures.

I'm going to read data from the sqlDB and at some point load it into the appropriate objects.

I have been programming in java for a while, so my first instinct is to get the data into the result set, then iterate through the result set and map the data into my objects.

I'm aware of the DataSets and dataAdapters, however, I'm not entirely sure what one I should be using.

I'm not interested in the code, just some general advise on data structures in VB.Net and how you would go about mapping the data from MS SQL Server onto VB.net objects.

Thank you
0
Comment
Question by:Inglorious
  • 2
  • 2
  • 2
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24802261
You say "I'm not entirely sure what one I should be using." DataAdapters and DataSets actually work together. A DataSet will be like your ResultSet--it holds the data you retrieved from the DB (in DataTables!). A DataAdapter manages retrieval and updating of data held in a DataSet. For example, the DataAdapter holds the SQL to retrieve and update the DB to/from the DataSet within it SelectCommand and UpdateCommand properties, respectively. All you have to do is something like dataAdapterName.Fill(dataSetName) to load data from DB to DataSet.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24802306
There is a specific command to commit changes made to the DataSet to the DB, but I don't recall the name off the top of my head. An update example was lacking in my last post.

Also, I mentioned DataTables. DataSets consist of one or more DataTables hold the actual data. This allows you to have multiple queries/tables from the DB within a single Dataset. The column names of the DataTables will be those of the table selected or the columns/aliases of the select query.
0
 

Author Comment

by:Inglorious
ID: 24803076
Hey,

Thank you for your response.

I looked at the way DataSets work. Thank you very much for pointing me in that direction.

Is it a good idea, or is it actually possible to map records from the dataTables onto someObject, so that each record in a dataTable is an instance of some class.

Is it a good approach to get data from the dataSet, manualy load it into some object, load object into the array list and then work with that array list by invoking methods on the objects?
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 27

Accepted Solution

by:
VBRocks earned 50 total points
ID: 24804243
Inglorious - Yes, absolutely.  You can create your own custom classes with validate, etc., and create a new instance for each row in the DataTable.

There is a huge advantage to using DataTables, though, and that is that they automatically support binding, sorting and filter.  You don't have to do any programming for that to work!  It's very nice.

On the other hand, if you decide to create your own custom classes, then you have to create a list class, and implement the binding, sorting  and filter yourself, which is a lot of work.  And if you don't really understand that, then you might just want to go with ADO.NET.

Check out this book review I did at Amazon, it discusses this issue:

http://www.amazon.com/gp/cdp/member-reviews/AZIRONOELH2Y3/ref=cm_cr_pr_auth_rev?ie=UTF8&sort_by=MostRecentReview

0
 

Author Comment

by:Inglorious
ID: 24815247
Thank you very much for the response.

I actually know how to do it "long/hard" way, but I never came across data sets/tables, dataReaders and .Net  API in general.

Just finished the prototype - dataTables are indeed very flexible, porwerful and simple to use.

Thank you again :)
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 24815331
You're welcome!

If you're ever interested, there's a book that was written by David Sceppa, it's called "Programming ADO.NET 2.0 Core Reference", and it's an awesome book!  They may have 3.5/4.0 by now, because it's been a while since I bought that, but I keep it around as a reference.

    http://www.davidsceppa.net/

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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