Typed Dataset and Null Values

  • Thread starter Thread starter Elmer Miller
  • Start date Start date
E

Elmer Miller

I have found it very frustrating trying to work with typed datasets and null
values. I'm starting to wonder if the typed dataset is more trouble than it
is worth. The problem is partly solved by the 'NullValue' property of the
typed dataset, but this only really works for reference types. For value
types you always need to check if the field is null with IsFieldNameNull()
before trying to reference the field. This makes databinding to a strong
typed dataset impossible as far as I can tell.
Surely I'm not the only one to encounter this problem.
Could someone please explain the recommended 'Best Practices' for dealing
with strong typed datasets and databinding. Thanks.
 
Hi Elmer,


Elmer Miller said:
I have found it very frustrating trying to work with typed datasets and null
values. I'm starting to wonder if the typed dataset is more trouble than it
is worth. The problem is partly solved by the 'NullValue' property of the
typed dataset, but this only really works for reference types. For value
types you always need to check if the field is null with IsFieldNameNull()
before trying to reference the field. This makes databinding to a strong
typed dataset impossible as far as I can tell.

Use databinding like untyped DataSet:
textbox1.DataBindings.Add("Text", dataset.Tables[0], "Value");
It works since typed dataset is actually derived from untyped one.
I think that typed properties are more usefull within code than for
databinding.
Surely I'm not the only one to encounter this problem.
Could someone please explain the recommended 'Best Practices' for dealing
with strong typed datasets and databinding. Thanks.

See above.
 
Thanks Miha,
I feel stupid for not realizing how simple it was. I can even cast the
typed DataRow back to a regular DataRow whenever I want too. This works
great. Thanks again.

Miha Markic said:
Hi Elmer,


Elmer Miller said:
I have found it very frustrating trying to work with typed datasets and null
values. I'm starting to wonder if the typed dataset is more trouble than it
is worth. The problem is partly solved by the 'NullValue' property of the
typed dataset, but this only really works for reference types. For value
types you always need to check if the field is null with IsFieldNameNull()
before trying to reference the field. This makes databinding to a strong
typed dataset impossible as far as I can tell.

Use databinding like untyped DataSet:
textbox1.DataBindings.Add("Text", dataset.Tables[0], "Value");
It works since typed dataset is actually derived from untyped one.
I think that typed properties are more usefull within code than for
databinding.
Surely I'm not the only one to encounter this problem.
Could someone please explain the recommended 'Best Practices' for dealing
with strong typed datasets and databinding. Thanks.

See above.
 
Back
Top