[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

Return a NULL dataset from a webservice ??!

Robbo

7/10/2003 5:52:00 PM

When my webservice returns a null dataset my application crashes. null
exception error. Has anyone experianced this ?
and wondering if anyone has a workaround.

here's a snipet of code i'm using. works great when the webservice returns a
result

Dim option2 As String =
data.Tables("stockresults").Rows(0)("option2").ToString
If option2 Is System.DBNull.Value Then
option2 = "nothing"
End If

Here's another error i get when it returns a null dataset

An unhandled exception of type 'System.IndexOutOfRangeException' occurred in
system.data.dll

Additional information: There is no row at position 0.
some other code i tryed.

Dim optionprice2 As String =
data.Tables("stockresults").Rows(0)("optionprice2").ToString
If optionprice2 Is System.DBNull.Value Or optionprice2 = "" Then
optionprice2 = "nothing"
End If
If optionprice2 <> "nothing" Then
optionprice2 = optionprice2.TrimStart(trims)
o2 = CSng(optionprice2)

End If
If optionprice2 = "nothing" Then
optionprice2 = ""
End If
3 Answers

Marina

7/10/2003 7:54:00 PM

0

If there are no rows, then that is just the way it is. Check to make sure
there is a row at position 0 before trying to access it.

"Robbo" <Drstripe-spamblock@hotmail.com> wrote in message
news:_JGdnSs0QqVBOpCiXTWJig@giganews.com...
> When my webservice returns a null dataset my application crashes. null
> exception error. Has anyone experianced this ?
> and wondering if anyone has a workaround.
>
> here's a snipet of code i'm using. works great when the webservice returns
a
> result
>
> Dim option2 As String =
> data.Tables("stockresults").Rows(0)("option2").ToString
> If option2 Is System.DBNull.Value Then
> option2 = "nothing"
> End If
>
> Here's another error i get when it returns a null dataset
>
> An unhandled exception of type 'System.IndexOutOfRangeException' occurred
in
> system.data.dll
>
> Additional information: There is no row at position 0.
> some other code i tryed.
>
> Dim optionprice2 As String =
> data.Tables("stockresults").Rows(0)("optionprice2").ToString
> If optionprice2 Is System.DBNull.Value Or optionprice2 = "" Then
> optionprice2 = "nothing"
> End If
> If optionprice2 <> "nothing" Then
> optionprice2 = optionprice2.TrimStart(trims)
> o2 = CSng(optionprice2)
>
> End If
> If optionprice2 = "nothing" Then
> optionprice2 = ""
> End If


Robbo

7/13/2003 1:19:00 PM

0

How can you do that check / is it if/then

If option2 Is System.DBNull.Value Then

??

Thanks,
Rob

Marina

7/14/2003 3:56:00 PM

0

DBNull is a NULL value in a database. This is not in any way related to a
null object.

Just check to make sure that there is at least one table, and that if there
is at least one table it has at least 1 row.

"Robbo" <Drstripe-spamblock@hotmail.com> wrote in message
news:uBSdnfc5VpXdwYyiU-KYvw@giganews.com...
> How can you do that check / is it if/then
>
> If option2 Is System.DBNull.Value Then
>
> ??
>
> Thanks,
> Rob