Formview Null Values

M

Matt MacDonald

Hi all,
I'm having an issue that's driving me crazy. I have a datatable that I
need to display all the information for on a page. So, instead of manually
coding every single column to a label, I decided it would be easier and
safer to use a formview to display it all, bound to an objectdatasource.
Sounds simple enough. The problem is that many of my fields could
potentially have null values, which produces an error similar to the
following when the formview is databound.

Conversion from type 'DBNull' to type 'Integer' is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Conversion from type
'DBNull' to type 'Integer' is not valid.

Source Error:

Line 3122: Get
Line 3123: Try
Line 3124: Return
CType(Me(Me.tableMFT_Products.CaloriesFromFatPercColumn),Integer)
Line 3125: Catch e As Global.System.InvalidCastException
Line 3126: Throw New
Global.System.Data.StrongTypingException("The value for column
'CaloriesFromFatPerc' in table 'MFT_Products' is DBNull.", e)


So now I'm back to having to hand check every field for nulls on the
databound event, which really isn't saving me any time. My whole reason for
using the formview was to be able to use the templates to have some control
on the way the data displayed. In a gridview or other databound controls,
the framework automatically ignores null values. Is there a way to make the
formview behave similarly?

Thanks,
Matt
 
S

Stan

Hi all,
  I'm having an issue that's driving me crazy.  I have a datatable that I
need to display all the information for on a page.  So, instead of manually
coding every single column to a label, I decided it would be easier and
safer to use a formview to display it all, bound to an objectdatasource.
Sounds simple enough.  The problem is that many of my fields could
potentially have null values, which produces an error similar to the
following when the formview is databound.

Conversion from type 'DBNull' to type 'Integer' is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Conversion from type
'DBNull' to type 'Integer' is not valid.

Source Error:

Line 3122:            Get
Line 3123:                Try
Line 3124:                    Return
CType(Me(Me.tableMFT_Products.CaloriesFromFatPercColumn),Integer)
Line 3125:                Catch e As Global.System.InvalidCastException
Line 3126:                    Throw New
Global.System.Data.StrongTypingException("The value for column
'CaloriesFromFatPerc' in table 'MFT_Products' is DBNull.", e)

So now I'm back to having to hand check every field for nulls on the
databound event, which really isn't saving me any time.  My whole reason for
using the formview was to be able to use the templates to have some control
on the way the data displayed.  In a gridview or other databound controls,
the framework automatically ignores null values.  Is there a way to make the
formview behave similarly?

Thanks,
  Matt

FormView is normally just as tolerant of null values as the other data
control types you mention. The exception is being thrown by what looks
like hand-written code to convert the field to an integer.
 
M

Matt MacDonald

I wish it were, but all I'm doing is attaching my datasource to the formview
and running it. I'm not doing anything in the code behind, and while the
type of that column is integer, it's all being handled from the dataset. No
manual code has been written.

Hi all,
I'm having an issue that's driving me crazy. I have a datatable that I
need to display all the information for on a page. So, instead of manually
coding every single column to a label, I decided it would be easier and
safer to use a formview to display it all, bound to an objectdatasource.
Sounds simple enough. The problem is that many of my fields could
potentially have null values, which produces an error similar to the
following when the formview is databound.

Conversion from type 'DBNull' to type 'Integer' is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Conversion from type
'DBNull' to type 'Integer' is not valid.

Source Error:

Line 3122: Get
Line 3123: Try
Line 3124: Return
CType(Me(Me.tableMFT_Products.CaloriesFromFatPercColumn),Integer)
Line 3125: Catch e As Global.System.InvalidCastException
Line 3126: Throw New
Global.System.Data.StrongTypingException("The value for column
'CaloriesFromFatPerc' in table 'MFT_Products' is DBNull.", e)

So now I'm back to having to hand check every field for nulls on the
databound event, which really isn't saving me any time. My whole reason
for
using the formview was to be able to use the templates to have some
control
on the way the data displayed. In a gridview or other databound controls,
the framework automatically ignores null values. Is there a way to make
the
formview behave similarly?

Thanks,
Matt

FormView is normally just as tolerant of null values as the other data
control types you mention. The exception is being thrown by what looks
like hand-written code to convert the field to an integer.
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top