Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid Cast Exception when checkbox value is null

Status
Not open for further replies.

Gill1978

Programmer
Jun 12, 2001
277
GB
Hi,

When I run my web page the gridview displays all the checkboxes fine, however when I select the link to the same page from the menu i get the following error:

"When casting from a number, the value must be a number less than infinity. Make sure the source type is convertible to the destination type."

I know that the value from the database is NULL, but why does it work when I load the page initailly but not when I use the link?

Thanks for any help

Julie
 
How are you "running" it the first time when it works? Is it a PostBack/!PostBack issue?

What line of code is the error being thrown on?

What value from the database?

Not enough information to help you here.

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Ahhh sorry about that ... realised it was because of bad data which is being caused by my update statement.

I'm new to .NET and the update statement that's generated isn't working as I thought it should. The datasource for the fields in my formview is pulling back all the fields in my table. I am only displaying a handful of the fields on the page. When I select the Update (auto generated by asp) link button the fields on that screen are updated correctly in the database but all the other fields in my table (that aren't displayed on the page) are updated to NULL.

So I changed the autogenerated update query to update just the fields that are on the screen, this now doesn't update any fields as all, and doesn't error out either?!?!

The update statement looks like this:
Code:
UpdateCommand="UPDATE dbo.EmployeeDetails SET ReqEU = @ReqEU, ReqGCM = @ReqGCM, ReqGCMTemp = @ReqGCMTemp, ReqGCMoverseas = @ReqGCMoverseas, ReqSales = @ReqSales, ReqTrading = @ReqTrading, ReqResearch = @ReqResearch, ReqCapMark = @ReqCapMark, ReqDCM = @ReqDCM, ReqCorpBank = @ReqCorpBank, ReqCorpFinan = @ReqCorpFinan, ReqOperations = @ReqOperations, ReqManSup = @ReqManSup, ReqZTD = @ReqZTD, ReqZAMPB = @ReqZAMPB, ReqZAMAM = @ReqZAMAM, ReqOther = @ReqOther, DateRecEU = @DateRecEU, DateRecGCM = @DateRecGCM, DateRecGCMTemp = @DateRecGCMTemp, DateRecGCMoverseas = @DateRecGCMoverseas, DateRecSales = @DateRecSales, DateRecTrading = @DateRecTrading, DateRecResearch = @DateRecResearch, DateRecCapMark = @DateRecCapMark, DateRecDCM = @DateRecDCM, DateRecCorpBank = @DateRecCorpBank, DateRecCorpFinan = @DateRecCorpFinan, DateRecOperations = @DateRecOperations, DateRecManSup = @DateRecManSup, DateRecZTD = @DateRecZTD, DateRecZAMPB = @DateRecZAMPB, DateRecZAMAM = @DateRecZAMAM, DateRecOther = @DateRecOther, CommentsEU = @CommentsEU, CommentsGCM = @CommentsGCM, CommentsGCMTemp = @CommentsGCMTemp, CommentsGCMover = @CommentsGCMover, CommentsSales = @CommentsSales, CommentsTrading = @CommentsTrading, CommentsResearch = @CommentsResearch, CommentsCapMark = @CommentsCapMark, CommentsDCM = @CommentsDCM, CommentsCorpBank = @CommentsCorpBank, CommentsCorpFinan = @CommentsCorpFinan, CommentsOperations = @CommentsOperations, CommentsManSup = @CommentsManSup, CommentsZTD = @CommentsZTD, CommentsZAMPB = @CommentsZAMPB, CommentsZAMAM = @CommentsZAMAM, CommentsOther = @CommentsOther WHERE (EmployeeID = @original_EmployeeID)">

Has anyone come across this, I'm at a complete loss ... help

Thanks

Julie
 
In case someone else bashes their head against a wall over this ...

I realised, in the sqldatasource source code, I had the following line that obviously compared all values to see if they had changed. If so then do the update else the update was not executed.

Code:
ConflictDetection="CompareAllValues"

Thanks for all the help ...

Julie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top