Checking for Null in Function ?

Discussion in 'ASP .Net' started by luqman, Apr 23, 2007.

  1. luqman

    luqman Guest

    How can I check if dv recordcount isNull ?

    Best Regards,

    Luqman

    Function showRecords(byVal ItemID as Int16) as String
    Dim SqlArg as New DataSourceSelectArguments
    Dim dv As New System.Data.DataView
    dv=sqlDatasource.Select(SqlArg)

    If dv.Item(0).Rows.Count.Equals(System.DBNull.Value) then Exit Function

    Dim drRow asSystem.Data.DataRow=dv.Item(0).Row <---- Null Exception Error
    in this Line

    if drRow(0)>0 then
    showRecords="yes"
    End If

    End Function
    luqman, Apr 23, 2007
    #1
    1. Advertising

  2. On Apr 23, 12:19 pm, "luqman" <> wrote:
    > How can I check if dv recordcount isNull ?
    >
    > Best Regards,
    >
    > Luqman
    >
    > Function showRecords(byVal ItemID as Int16) as String
    > Dim SqlArg as New DataSourceSelectArguments
    > Dim dv As New System.Data.DataView
    > dv=sqlDatasource.Select(SqlArg)
    >
    > If dv.Item(0).Rows.Count.Equals(System.DBNull.Value) then Exit Function
    >
    > Dim drRow asSystem.Data.DataRow=dv.Item(0).Row <---- Null Exception Error
    > in this Line
    >
    > if drRow(0)>0 then
    > showRecords="yes"
    > End If
    >
    > End Function


    dv.Item(0).Rows.Count cannot be null

    A dataview I suppose can be a null

    but just check if number of rows is more than 0

    If dv.Item(0).Rows.Count = 0 then Exit Function
    Alexey Smirnov, Apr 23, 2007
    #2
    1. Advertising

  3. luqman

    luqman Guest

    Hi,

    I also checked using If dv.Item(0).Rows.Count = 0 then Exit Function but
    still its raising Null Exception.

    Best Regards,

    Luqman


    "Alexey Smirnov" <> wrote in message
    news:...
    > On Apr 23, 12:19 pm, "luqman" <> wrote:
    > > How can I check if dv recordcount isNull ?
    > >
    > > Best Regards,
    > >
    > > Luqman
    > >
    > > Function showRecords(byVal ItemID as Int16) as String
    > > Dim SqlArg as New DataSourceSelectArguments
    > > Dim dv As New System.Data.DataView
    > > dv=sqlDatasource.Select(SqlArg)
    > >
    > > If dv.Item(0).Rows.Count.Equals(System.DBNull.Value) then Exit Function
    > >
    > > Dim drRow asSystem.Data.DataRow=dv.Item(0).Row <---- Null Exception

    Error
    > > in this Line
    > >
    > > if drRow(0)>0 then
    > > showRecords="yes"
    > > End If
    > >
    > > End Function

    >
    > dv.Item(0).Rows.Count cannot be null
    >
    > A dataview I suppose can be a null
    >
    > but just check if number of rows is more than 0
    >
    > If dv.Item(0).Rows.Count = 0 then Exit Function
    >
    luqman, Apr 23, 2007
    #3
  4. luqman

    David Guest

    That can happen if you have no tables in your dataview.

    You need to check earlier than your DV, or you could stick a try/catch
    around this line.

    --
    Best regards,
    Dave Colliver.
    http://www.AshfieldFOCUS.com
    ~~
    http://www.FOCUSPortals.com - Local franchises available


    "luqman" <> wrote in message
    news:...
    > Hi,
    >
    > I also checked using If dv.Item(0).Rows.Count = 0 then Exit Function but
    > still its raising Null Exception.
    >
    > Best Regards,
    >
    > Luqman
    >
    >
    > "Alexey Smirnov" <> wrote in message
    > news:...
    >> On Apr 23, 12:19 pm, "luqman" <> wrote:
    >> > How can I check if dv recordcount isNull ?
    >> >
    >> > Best Regards,
    >> >
    >> > Luqman
    >> >
    >> > Function showRecords(byVal ItemID as Int16) as String
    >> > Dim SqlArg as New DataSourceSelectArguments
    >> > Dim dv As New System.Data.DataView
    >> > dv=sqlDatasource.Select(SqlArg)
    >> >
    >> > If dv.Item(0).Rows.Count.Equals(System.DBNull.Value) then Exit Function
    >> >
    >> > Dim drRow asSystem.Data.DataRow=dv.Item(0).Row <---- Null Exception

    > Error
    >> > in this Line
    >> >
    >> > if drRow(0)>0 then
    >> > showRecords="yes"
    >> > End If
    >> >
    >> > End Function

    >>
    >> dv.Item(0).Rows.Count cannot be null
    >>
    >> A dataview I suppose can be a null
    >>
    >> but just check if number of rows is more than 0
    >>
    >> If dv.Item(0).Rows.Count = 0 then Exit Function
    >>

    >
    >
    David, Apr 23, 2007
    #4
  5. luqman

    luqman Guest

    Hi David,

    Thanks a lot, I just figured out that I was not passing a parameter value to
    my Sql Data Source.

    Best Regards,

    Luqman

    "David" <> wrote in message
    news:...
    > That can happen if you have no tables in your dataview.
    >
    > You need to check earlier than your DV, or you could stick a try/catch
    > around this line.
    >
    > --
    > Best regards,
    > Dave Colliver.
    > http://www.AshfieldFOCUS.com
    > ~~
    > http://www.FOCUSPortals.com - Local franchises available
    >
    >
    > "luqman" <> wrote in message
    > news:...
    > > Hi,
    > >
    > > I also checked using If dv.Item(0).Rows.Count = 0 then Exit Function but
    > > still its raising Null Exception.
    > >
    > > Best Regards,
    > >
    > > Luqman
    > >
    > >
    > > "Alexey Smirnov" <> wrote in message
    > > news:...
    > >> On Apr 23, 12:19 pm, "luqman" <> wrote:
    > >> > How can I check if dv recordcount isNull ?
    > >> >
    > >> > Best Regards,
    > >> >
    > >> > Luqman
    > >> >
    > >> > Function showRecords(byVal ItemID as Int16) as String
    > >> > Dim SqlArg as New DataSourceSelectArguments
    > >> > Dim dv As New System.Data.DataView
    > >> > dv=sqlDatasource.Select(SqlArg)
    > >> >
    > >> > If dv.Item(0).Rows.Count.Equals(System.DBNull.Value) then Exit

    Function
    > >> >
    > >> > Dim drRow asSystem.Data.DataRow=dv.Item(0).Row <---- Null Exception

    > > Error
    > >> > in this Line
    > >> >
    > >> > if drRow(0)>0 then
    > >> > showRecords="yes"
    > >> > End If
    > >> >
    > >> > End Function
    > >>
    > >> dv.Item(0).Rows.Count cannot be null
    > >>
    > >> A dataview I suppose can be a null
    > >>
    > >> but just check if number of rows is more than 0
    > >>
    > >> If dv.Item(0).Rows.Count = 0 then Exit Function
    > >>

    > >
    > >

    >
    >
    luqman, Apr 23, 2007
    #5
  6. On Apr 23, 1:24 pm, "David"
    <> wrote:
    > That can happen if you have no tables in your dataview.
    >
    > You need to check earlier than your DV, or you could stick a try/catch
    > around this line.
    >
    > --
    > Best regards,
    > Dave Colliver.http://www.AshfieldFOCUS.com
    > ~~http://www.FOCUSPortals.com- Local franchises available
    >
    > "luqman" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > Hi,

    >
    > > I also checked using If dv.Item(0).Rows.Count = 0 then Exit Function but
    > > still its raising Null Exception.

    >
    > > Best Regards,

    >
    > > Luqman

    >
    > > "Alexey Smirnov" <> wrote in message
    > >news:...
    > >> On Apr 23, 12:19 pm, "luqman" <> wrote:
    > >> > How can I check if dv recordcount isNull ?

    >
    > >> > Best Regards,

    >
    > >> > Luqman

    >
    > >> > Function showRecords(byVal ItemID as Int16) as String
    > >> > Dim SqlArg as New DataSourceSelectArguments
    > >> > Dim dv As New System.Data.DataView
    > >> > dv=sqlDatasource.Select(SqlArg)

    >
    > >> > If dv.Item(0).Rows.Count.Equals(System.DBNull.Value) then Exit Function

    >
    > >> > Dim drRow asSystem.Data.DataRow=dv.Item(0).Row <---- Null Exception

    > > Error
    > >> > in this Line

    >
    > >> > if drRow(0)>0 then
    > >> > showRecords="yes"
    > >> > End If

    >
    > >> > End Function

    >
    > >> dv.Item(0).Rows.Count cannot be null

    >
    > >> A dataview I suppose can be a null

    >
    > >> but just check if number of rows is more than 0

    >
    > >> If dv.Item(0).Rows.Count = 0 then Exit Function- Hide quoted text -

    >
    > - Show quoted text -


    Try to add this

    If IsNothing(dv.Table) Then Exit Function

    Note, that Exit Function will return nothing from your function.
    Maybe it is better to Return String.Empty or any other value...
    Alexey Smirnov, Apr 23, 2007
    #6
    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. Troy

    Checking For Null DB Fields

    Troy, Aug 21, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    385
    Jeremy Cowles
    Aug 21, 2003
  2. ]-[aTc]-[
    Replies:
    6
    Views:
    20,165
    shebmanchester
    Nov 28, 2011
  3. Jimmy Crider
    Replies:
    3
    Views:
    444
    Chad Z. Hower aka Kudzu
    Feb 18, 2004
  4. excelleinc.com
    Replies:
    1
    Views:
    1,391
    Hermit Dave
    Sep 10, 2004
  5. Replies:
    5
    Views:
    26,422
    Mike Schilling
    Mar 29, 2006
Loading...

Share This Page