473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Formview Null Values

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.CaloriesFromFatPercC olumn),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
Jun 27 '08 #1
2 2345
On 25 Apr, 17:15, "Matt MacDonald" <matts...@hotmail.comwrote:
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.CaloriesFromFatPercC olumn),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 reasonfor
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 makethe
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.
Jun 27 '08 #2
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.

"Stan" <go****@philphall.me.ukwrote in message
news:61**********************************@p25g2000 hsf.googlegroups.com...
On 25 Apr, 17:15, "Matt MacDonald" <matts...@hotmail.comwrote:
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.CaloriesFromFatPercC olumn),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.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ottar | last post by:
I have a few numeric fields, and when I update i get the error: "Input string was not in a correct format". Next line:" System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&...
1
by: pete | last post by:
I seem unable to get the FormView with the SqlDataSource control in ASP.NET 2.0 beta 2 to insert into my MySQL 4.11 database corectly. When I run the page and click on the Insert link a SQL insert...
2
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
2
by: Gary Homewood | last post by:
Where can I specify a default value for a column when using a FormView? Specifically, I have a checkbox for a column of bit datatype on my database, and I'd like to default it to checked for insert...
7
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the...
4
by: Rob | last post by:
Hey all, So.. a simple FormView/SqlDataSource to handle inserting records into a table. The table has a primary key that the user enters (eg DiscountCode). If the user enters a duplicate the...
4
by: J055 | last post by:
Hi I have 2 update buttons in my FormView ('Apply' and 'OK'). I want both buttons to update the data source but the 'OK' button should redirect afterwards. I can see which button is clicked...
1
by: Dave E | last post by:
Hi all, == brief version == using ASP 2.0, I have a ddl inside a formview. On update, if the ddl starts as NULL, no update happens. If the ddl has a bound value that is not NULL, then all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.