471,066 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Passing Null to Function ?

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


Apr 23 '07 #1
2 1060
On Apr 23, 3:08 pm, "luqman" <pearls...@cyber.net.pkwrote:
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

Apr 23 '07 #2
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.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*********************************************
Think outside the box!
*********************************************
"luqman" <pe*******@cyber.net.pkwrote in message
news:ee**************@TK2MSFTNGP04.phx.gbl...
>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

Apr 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Pushkar Pradhan | last post: by
2 posts views Thread by Morgan | last post: by
5 posts views Thread by Bucky Pollard | last post: by
7 posts views Thread by Jake Thompson | last post: by
12 posts views Thread by Andrew Bullock | last post: by
12 posts views Thread by Mike | last post: by
8 posts views Thread by Ivan Liu | last post: by
18 posts views Thread by sanjay | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.