Checking for Null in Function ?

L

luqman

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
 
G

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

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
 
L

luqman

Hi,

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

Best Regards,

Luqman
 
L

luqman

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
 
G

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








- 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...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top