collections / OO approach on datasets

  • Thread starter Thread starter Christian H
  • Start date Start date
C

Christian H

Hi!

I was wondering if there is a "better" way to use dataset's instead of using
"someset.Tables["sometable"].Rows[index][index]" in order to get the content
out of the datatables. I think "collections" is what I'm looking for, though
I'm really not sure.

I have a dataset that has 8 tables in it. If I used collections or
something, then I could make it a little easier to work on, so that I didn't
have to keep track of coloumn names everytime I need to use the dataset
somewhere.

It would be great if anyone has some URL's or examples I could look at, on
how to create collections from a dataset.

C.H
 
Investigate strongly typed DataSets.

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Hi!

I was wondering if there is a "better" way to use dataset's instead of
using "someset.Tables["sometable"].Rows[index][index]" in order to get
the content out of the datatables. I think "collections" is what I'm
looking for, though I'm really not sure.

I have a dataset that has 8 tables in it. If I used collections or
something, then I could make it a little easier to work on, so that I
didn't have to keep track of coloumn names everytime I need to use the
dataset somewhere.

It would be great if anyone has some URL's or examples I could look
at, on how to create collections from a dataset.

C.H

DataSet.Tables is a collection of DataTable
DataTable.Rows is a collection of DataRow

You are already using collections. In what way do you expect it to get
easier? Are you looking for a "strongly typed dataset" (see help files)?
Or do you want a standard collection of objects that represent a table,
where each item in the collection represents a single row, such as...

public class Employees:CollectionBase
{
public void Add(Employee emp){...}
public Employee this[int index]{get;}
...etc...
public void Fill(DataTable dt)
{ //for each row - create new employee, call Fill,
// and add to collection
}
}
public class Employee
{
public string FirstName{get;set;}
public string LastName{get;set;}
... etc ...
public void Fill(DataRow dr){...}
// ^ fills properties given a row
}

This way is not any less code, it just makes a "business layer" component
that is more intuitive for the consumer (end user application) to use, and
can enforce any business rules.

I have an example of this in the latest template on the code generator site
referenced in my signature. It will generate the code you'd need for your
database. All you have to do is create the solution with 3 projects (one
for each application tier).
 
Back
Top