Null int/float columns with TableAdapters

N

Nick Gilbert

Hi,

I have a database table which has some "float" columns which allow
nulls. I have created a TableAdapter to view this table.

If I open the TableAdapter and there are null values for some of the
float columns then an exception is thrown:

Line 2136: try {
Line 2137: return
((double)(this[this.tableProducts.MaxPressureBarColumn]));
Line 2138: }
Line 2139: catch (System.InvalidCastException e) {

[StrongTypingException: The value for column 'MaxPressureBar' in table
'Products' is DBNull.]

With string values, you can change the NullValue property to "null" in
the xsd file and all is well - however it won't let you do this for
anything other than strings even though .NET 2 supports null values for
ints floats and decimals etc...

Is there any way I can make this work? Or some kind of workaround I can use?

The only thing I can think to do is prevent the float columns from being
null and use 0 instead. But for some of the columns, zero is a valid
value and I need to be able to distinguish between 0 and null in the code.

Help!

Nick...
 
W

Walter Wang [MSFT]

Hi Nick,

This is a known issue of typed DataSet in .NET 2.0. The generated code
snippet is actually from the typed DataSet (for example:
DataSet1.Table3Row) rather than the TableAdapter. As the TableAdapter's
documentation (http://msdn2.microsoft.com/en-us/library/bz9tthwx.aspx)
claimed: The TableAdapters support nullable types Nullable(Of T) and T?.
You should see the Insert or Update method of your TableAdapter does use
"System.Nullable<double>" as parameter data type.

We looked really closely at extending typed DataSet to support Nullable
types. However, Nullable types were added a bit late in the cycle and we
just didn't have the time to work out all the plumbing issues up and down
the stack. Because typed DataSet serializes into untyped DataSets, and due
to the way DataBinding works with Views, adding Nullable types in the
strongly typed DataSet was problematic. Another issue is related to
compatibility with .NET 1.x.

There's already a related feedbak on this issue:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedbac
kID=121229

As the product team responded, it will be considered for a future
enhancement. Thank you for your feedback!

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top