Passing Null to Function ?

L

luqman

I have defined custom binding in DetailView Textbox.

<%# ShowParent(Eval("ParentID")) %>

Its calling a ShowParent() function which is as under:


The problem is that if ParentID field is Null,then the above line passes the
Null to function and error occurs when converting DBNull to Int16.

How can I detect if ParentID is Null or not ?


Function ShowParent(byVal parentID as Int16) as String

'my code

End Sub


Best Regards,

Luqman
 
G

Guest

I have defined custom binding in DetailView Textbox.

<%# ShowParent(Eval("ParentID")) %>

Its calling a ShowParent() function which is as under:

The problem is that if ParentID field is Null,then the above line passes the
Null to function and error occurs when converting DBNull to Int16.

How can I detect if ParentID is Null or not ?

Function ShowParent(byVal parentID as Int16) as String

'my code

End Sub

Best Regards,

Luqman

Try to pass an object to the function

Function ShowParent(byVal parentID) as String

and check there

If Not IsDbNull(parentID) then
Dim parentID_int as Int16 = Convert.ToInt16(parentID)
....
End If
 
C

Cowboy \(Gregory A. Beamer\)

My first thought is switching to a nullable type (available in 2.0). The
type would be short? in C#, changing the signature to:

ShowParent(short? val)

This may still not work, as the issue may not be in the parameter.
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top