By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

Handling empty relation to child object

P: n/a
In a Typed Dataset, is there a way on the xs:keyref tag that I can specify
how to handle null child objects?

For example, if I have an Invoice table, where a ClientID key is used to
create a reference to a Clients Table by it's ID Column. On the Clients
table I have a Name element.
In the calling code I do :
x = myInvoice.Reference
x = myInvoice.Amount
x = myInvoice.Rate
x = myInvoice.Client.Name
this will throw an error if, for whatever reason, the Client does not exist.
How can I get it to return an empty string instead of having to do :

If Not myInvoice.Client = Nothing Then
x = myInvoice.Client.Name
else
x = ""
End If
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
A trck I always use is this:

x = myInvoice.Client.Name & ""

Hth,
Martin
"Andrew" <an*****@nospam.dbasplus.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
In a Typed Dataset, is there a way on the xs:keyref tag that I can specify
how to handle null child objects?

For example, if I have an Invoice table, where a ClientID key is used to
create a reference to a Clients Table by it's ID Column. On the Clients
table I have a Name element.
In the calling code I do :
x = myInvoice.Reference
x = myInvoice.Amount
x = myInvoice.Rate
x = myInvoice.Client.Name
this will throw an error if, for whatever reason, the Client does not exist. How can I get it to return an empty string instead of having to do :

If Not myInvoice.Client = Nothing Then
x = myInvoice.Client.Name
else
x = ""
End If

Nov 20 '05 #2

P: n/a
Thanks for the reply Martin, but that still throws and exception because
myInvoice.Client is Nothing.
Or am I missing something?

"Martin" <am*******@nospam.hotmail.com> wrote in message
news:uG*************@TK2MSFTNGP12.phx.gbl...
A trck I always use is this:

x = myInvoice.Client.Name & ""

Hth,
Martin
"Andrew" <an*****@nospam.dbasplus.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
In a Typed Dataset, is there a way on the xs:keyref tag that I can specify how to handle null child objects?

For example, if I have an Invoice table, where a ClientID key is used to
create a reference to a Clients Table by it's ID Column. On the Clients
table I have a Name element.
In the calling code I do :
x = myInvoice.Reference
x = myInvoice.Amount
x = myInvoice.Rate
x = myInvoice.Client.Name
this will throw an error if, for whatever reason, the Client does not

exist.
How can I get it to return an empty string instead of having to do :

If Not myInvoice.Client = Nothing Then
x = myInvoice.Client.Name
else
x = ""
End If


Nov 20 '05 #3

P: n/a
No, you're not missing anything, I did.

I missed the 'Client' in between the dots.

In this case, sorry but I don't know any other way than to test if client =
nothing...


"Andrew" <an*****@nospam.dbasplus.com> wrote in message
news:Od**************@TK2MSFTNGP12.phx.gbl...
Thanks for the reply Martin, but that still throws and exception because
myInvoice.Client is Nothing.
Or am I missing something?

"Martin" <am*******@nospam.hotmail.com> wrote in message
news:uG*************@TK2MSFTNGP12.phx.gbl...
A trck I always use is this:

x = myInvoice.Client.Name & ""

Hth,
Martin
"Andrew" <an*****@nospam.dbasplus.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
In a Typed Dataset, is there a way on the xs:keyref tag that I can specify how to handle null child objects?

For example, if I have an Invoice table, where a ClientID key is used to create a reference to a Clients Table by it's ID Column. On the Clients table I have a Name element.
In the calling code I do :
x = myInvoice.Reference
x = myInvoice.Amount
x = myInvoice.Rate
x = myInvoice.Client.Name
this will throw an error if, for whatever reason, the Client does not

exist.
How can I get it to return an empty string instead of having to do :

If Not myInvoice.Client = Nothing Then
x = myInvoice.Client.Name
else
x = ""
End If



Nov 20 '05 #4

P: n/a
What if you just did

Try
x = myInvoice.Client.Name
Catch
x = ""
End Try

It's essentially the same thing, but you won't have to check for Client =
Nothing. I'm not sure if this is faster than your way, though.

-J

"Andrew" <an*****@nospam.dbasplus.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
In a Typed Dataset, is there a way on the xs:keyref tag that I can specify
how to handle null child objects?

For example, if I have an Invoice table, where a ClientID key is used to
create a reference to a Clients Table by it's ID Column. On the Clients
table I have a Name element.
In the calling code I do :
x = myInvoice.Reference
x = myInvoice.Amount
x = myInvoice.Rate
x = myInvoice.Client.Name
this will throw an error if, for whatever reason, the Client does not exist. How can I get it to return an empty string instead of having to do :

If Not myInvoice.Client = Nothing Then
x = myInvoice.Client.Name
else
x = ""
End If

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.