Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Null Checker

Reply
Thread Tools

Null Checker

 
 
Big E
Guest
Posts: n/a
 
      06-07-2004
I'm using ASP.Net and SQL Server. I'm breaking up the Phone Number into 3
sections for a form. When the value is Null I recieve Cast from type
'DBNull' to type 'String' is not valid.

I'm using a Null checker as seen below. When using this without the Left or
Mid it will work.

Thanks.



txtWorkPhone1.Text =
StringNullHelper(Left(dsReg.Tables("tblProspect"). Rows(0)("WorkPhone"), 3))

txtWorkPhone2.Text =
StringNullHelper(Mid(dsReg.Tables("tblProspect").R ows(0)("WorkPhone"), 4,
3))

txtWorkPhone3.Text =
StringNullHelper(Mid(dsReg.Tables("tblProspect").R ows(0)("WorkPhone"), 7,
4))

----------------------------------------------------------------------------
----------------------

Public Function StringNullHelper(ByVal obj As Object) As String

If IsDBNull(obj) Then Return String.Empty

Return obj.ToString()

End Function


 
Reply With Quote
 
 
 
 
John Oakes
Guest
Posts: n/a
 
      06-07-2004
I don't think you can call LEFT or MID on a NULL value.

-John Oakes

"Big E" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I'm using ASP.Net and SQL Server. I'm breaking up the Phone Number into 3
> sections for a form. When the value is Null I recieve Cast from type
> 'DBNull' to type 'String' is not valid.
>
> I'm using a Null checker as seen below. When using this without the Left

or
> Mid it will work.
>
> Thanks.
>
>
>
> txtWorkPhone1.Text =
> StringNullHelper(Left(dsReg.Tables("tblProspect"). Rows(0)("WorkPhone"),

3))
>
> txtWorkPhone2.Text =
> StringNullHelper(Mid(dsReg.Tables("tblProspect").R ows(0)("WorkPhone"), 4,
> 3))
>
> txtWorkPhone3.Text =
> StringNullHelper(Mid(dsReg.Tables("tblProspect").R ows(0)("WorkPhone"), 7,
> 4))
>
> --------------------------------------------------------------------------

--
> ----------------------
>
> Public Function StringNullHelper(ByVal obj As Object) As String
>
> If IsDBNull(obj) Then Return String.Empty
>
> Return obj.ToString()
>
> End Function
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Checker that's better than the normal syntax checker Jacob Grover Ruby 5 07-18-2008 05:07 AM
MSN BLOCK CHECKER-MSN STATUS CHECKER-MSN PROBLEMS Pager O Rama Digital Photography 0 04-04-2006 06:58 PM
MSN BLOCK CHECKER-MSN STATUS CHECKER-MSN PROBLEMS Pager O Rama ASP General 0 04-04-2006 06:41 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM



Advertisments