Re: Cast from type 'DBNull' to type 'String' is not valid.

From: Daniel Fisher\(lennybacon\) (info_at_(removethis)lennybacon.com)
Date: 12/15/04


Date: Wed, 15 Dec 2004 17:38:06 +0100

ClientReader.GetValue(0).ToString()
is not so nice cause you set the num of th column and not the name, but
works.

-- 
Daniel Fisher(lennybacon)
 MCP ASP.NET C#
 Blog: http://www.lennybacon.com/
"tshad" <tscheiderich@ftsolutions.com> wrote in message 
news:%232b0YNs4EHA.1524@TK2MSFTNGP09.phx.gbl...
> The error I am getting is:
>
> *******************************************************************
> Exception Details: System.InvalidCastException: Cast from type 'DBNull' to 
> type 'String' is not valid.
>
> Source Error:
>
> Line 144:   firstName.text = ClientReader("firstName")
> Line 145:   lastName.text = ClientReader("lastName")
> Line 146:   middleName.text = ClientReader("middleName")   <------
> Line 147:   fullName.text = ClientReader("fullName")
> Line 148:   address1.text = ClientReader("address1")
> *******************************************************************
>
> The code I am getting the error in is:
>
>  if ClientReader.Read then
>   applicantID.text = ClientReader("applicantID")
>   firstName.text = ClientReader("firstName")
>   lastName.text = ClientReader("lastName")
>   middleName.text = ClientReader("middleName")
>   fullName.text = ClientReader("fullName")
>   allowedWorkUS.text = ClientReader("allowedWorkUS")
>  end if
>
> How would I best do this?  Do I have to check for null for each of my 
> variables everytime I read a record?
>
> Thanks,
>
> Tom.
> 


Relevant Pages

  • Re: file.move to unc causes error
    ... Daniel Fisher ... MCP ASP.NET C# ... Blog: http://www.lennybacon.com/ ... "Michael McLaughlin" wrote in ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Title-tag per Code ändern
    ... Daniel Fisher ... MCP ASP.NET C# ... Blog: http://www.lennybacon.com/ ... "Alexander Szigetvary" wrote in message ...
    (microsoft.public.de.german.entwickler.dotnet.asp)
  • Re: code-ausführung in einem template
    ... Daniel Fisher ... "Capior" wrote in message ... >> MCP ASP.NET C# ... >> Blog: http://www.lennybacon.com/ ...
    (microsoft.public.de.german.entwickler.dotnet.asp)
  • Re: Tutorials
    ... Daniel Fisher ... MCP C# ASP.NET ... Blog: http://www.lennybacon.com/ ... "cashdeskmac" wrote in message ...
    (microsoft.public.dotnet.security)
  • Re: URL Rewriting ?
    ... > Daniel Fisher ... >> MCP C# ASP.NET ... >>hab da ein kleines Problem. ... >>THX und Gruss ...
    (microsoft.public.de.german.entwickler.dotnet.asp)