Expose a datatable column as a property?

  • Thread starter Thread starter Ramil Domingo
  • Start date Start date
R

Ramil Domingo

Hi All,

I would like to know if there is a way I could expose my column from a
datatable of strongly-typed dataset as a property without literally adding
the code of creating a property? I mean, instead of using
Dataset.DataTable.Rows("ColumnName") I could directly use
Dataset.DataTable.Rows.ColumnName. Is this possible?

TIA.

Ramil Domingo
Developer
 
Ramil:

If you are using a STD, then as soon as you type DataSet.MyTable. Your
column should be one of the options. If your datatable is a property of a
class, or if your column is, you should (IMHO) still probably make it a
property so you don't break encapsulation, but if you mean referring to it
internally...then you should be able to reference it directly. That's one
of the many benefits to using STD's
 
Hi William,

Thanks for the reply but unfortunately this does not work when you try to
access the column outside the assembly where the STD is located. I think
its because of the fact that the columns are tagged as "Friend" and can only
be accessed within the same assembly. Is there a way I could override this
setting at design-time?

TIA,

Ramil Domingo
Developer
 
If you stick the Dataset in SomeClass and one of SomeClass's Public
properties is SomeDataColumn...who's get/set controls the value fo the given
column, won't that do it for you?
 
Ok, so what's the benefit of addressing the column using the name? Easier
coding? Faster performance? Well, (as I describe in my book) there are lots
of folks that find strongly typed DataSets a bit tough to setup and manage.
There are alternatives that give you many of the same benefits. My choice is
using an enumeration.

Enum enuCols
AuthorName
YearBorn
Age
End Enum

....
myDataSet.Rows(n).items(enuCols.AuthorName) = "Fred"

The enumerations don't have to match the names used in the columns--just the
order and number. Tests show that by using enumerations (or simply ordinals)
that the performance is 90% what you get with strongly typed
DataSets--without the hassle.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
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.
__________________________________
 
Hello Bill
Tests show that by using enumerations (or simply ordinals)
that the performance is 90% what you get with strongly typed
DataSets--without the hassle.

Are you saying that MyDS.MyTable.FieldName is faster than
MyDS.MyTable.Item(MyEnum.Fieldname) ?? It has been my understanding that
enums or direct integer references where the quickest.

Ibrahim
 
My tests (albeit somewhat unscientific) show that strongly typed object
references are faster--it's not by much though.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
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.
__________________________________
 
heh, I guess I am going to have to go back over my own conclusions.

Could you tell me how you are setting up your tests? How many fields are in
your test source? I may have been giving wrong advice based upon my own
observations and really need to be sure on this subject.

Thanks
Ibrahim
 
The tests (run in both VB.NET and C#) looped through referencing about 40
(IIRC) fields of a DataSet using a variety of addressing techniques
including strongly typed. The source and results are published in my book.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
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.
__________________________________
 
heh...OK...I'll go buy the book Monday.



William (Bill) Vaughn said:
The tests (run in both VB.NET and C#) looped through referencing about 40
(IIRC) fields of a DataSet using a variety of addressing techniques
including strongly typed. The source and results are published in my book.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
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.
__________________________________

are
 
Hi William,

Thank you for the reply. Yes it would solve my problem and I agree. I just
want to know if I could get off the part of coding every column as a
property and just maybe let the dataset generated code handle that for me.
I know that the data columns are "Friend" property but I would like to find
out if there is a way I could change it to "Public" inside the generated
code. Is there a serializer or some sort that could tweak a little the
code-generated by the dataset?

TIA & Cheers.

Ramil Domingo
Developer
 
Back
Top