Null Checker

Discussion in 'ASP .Net' started by Big E, Jun 7, 2004.

  1. Big E

    Big E Guest

    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").Rows(0)("WorkPhone"), 4,
    3))

    txtWorkPhone3.Text =
    StringNullHelper(Mid(dsReg.Tables("tblProspect").Rows(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
    Big E, Jun 7, 2004
    #1
    1. Advertising

  2. Big E

    John Oakes Guest

    I don't think you can call LEFT or MID on a NULL value.

    -John Oakes

    "Big E" <> wrote in message
    news:%...
    > 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").Rows(0)("WorkPhone"), 4,
    > 3))
    >
    > txtWorkPhone3.Text =
    > StringNullHelper(Mid(dsReg.Tables("tblProspect").Rows(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
    >
    >
    John Oakes, Jun 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kivak Wolf
    Replies:
    2
    Views:
    10,059
    Kivak Wolf
    Jun 28, 2005
  2. vizlab
    Replies:
    3
    Views:
    4,184
    Michael Bar-Sinai
    Oct 17, 2007
  3. Replies:
    5
    Views:
    26,507
    Mike Schilling
    Mar 29, 2006
  4. Pager O Rama

    MSN BLOCK CHECKER-MSN STATUS CHECKER-MSN PROBLEMS

    Pager O Rama, Apr 4, 2006, in forum: ASP General
    Replies:
    0
    Views:
    225
    Pager O Rama
    Apr 4, 2006
  5. Jacob Grover
    Replies:
    5
    Views:
    304
    Jacob Grover
    Jul 18, 2008
Loading...

Share This Page