Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2004, 03:05 PM
Registered User
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cast from type 'DBNull' to type 'String' is not va

Getting this error
can any one please help me

Error : Cast from type 'DBNull' to type 'String' 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: Cast from type 'DBNull' to type 'String' is not valid.

Source Error:


Line 83: Dim tcellcoldata As New TableCell
Line 84: 'a = EmptyIf(New LiteralControl(dr(dc.ColumnName.ToString)))
Line 85: tcellcoldata.Controls.Add(New LiteralControl(dr(dc.ColumnName.ToString)))
Line 86: 'tcellcoldata.Controls.Add()
Line 87: trow.Cells.Add(tcellcoldata)




 
Old August 30th, 2004, 09:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You cant convert a NULL to a string.

dc.ColumnName is likely Null.

If you step through you can check the value during the run.

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
 
Old August 30th, 2004, 10:27 AM
Registered User
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can u help me how to rectify this error and make changes to the code

 
Old August 30th, 2004, 10:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You rectify the error by making your data non-null.

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
 
Old August 30th, 2004, 12:11 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Alternatively, you can check for a null value in your Code behind file:

If dr(dc.ColumnName) is DbNull.Value Then

Not sure if it will work like this because I don't know what dr and dc are, but generally comparing against DbNull.Value will do the trick.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cast from string 'OPEN' to type 'Double' is not va yasinirshad .NET Framework 1.x 1 August 12th, 2007 12:45 PM
Conversion from type 'DBNull' to type 'String' is GailCG ASP.NET 2.0 Basics 5 February 22nd, 2007 03:12 PM
Conversion from type 'DBNull' to type 'Boolean' is steve35719 VB Databases Basics 4 June 29th, 2006 06:13 PM
Cast from string "" to type 'Double' is not dounme ADO.NET 1 March 8th, 2005 01:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.