Solved

VB.Net: data structures

Posted on 2009-07-08
6
1,013 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

778 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