isnull ! gives error

J

Jim Bunton

Visual Web Developer 2008
using VB

D:\ . . . \WebsiteX\AppCode\WebRecordVb

** code snippet begin **
Imports Microsoft.VisualBasic

Public Class WebDbRecord
Private RestaurantId As Int32
Private FromWebOrRestaurant As Byte
Private SpeedOfService As Byte
'. . etc . .

Public Function IsValid() As Boolean
If isnull(RestaurantId) Then

End If
End Function
End Class

** code snippet end **

Why please is isnull creating a build error - name isnull is not declared ?
and what to do about it!

Jim Bunton
 
G

Gregory A. Beamer

Visual Web Developer 2008
using VB

D:\ . . . \WebsiteX\AppCode\WebRecordVb

** code snippet begin **
Imports Microsoft.VisualBasic

Public Class WebDbRecord
Private RestaurantId As Int32
Private FromWebOrRestaurant As Byte
Private SpeedOfService As Byte
'. . etc . .

Public Function IsValid() As Boolean
If isnull(RestaurantId) Then

End If
End Function
End Class


IsNull() is not native in VB.NET. Perhaps in the compatibility namespace
but not straight up.

Also, an int cannot have a null value. It is set to 0 when declared. you
can use a nullable int, but the test is:

If Not (RestaurantId.HasValue) Then

if you are using nullable int.
 
J

Jim Bunton

Thanks for your response to my posting Gregory.
I take your point about isnull(integervar) being inappropriate
I also found isEmpty() wasn't available

If Not (RestaurantId.HasValue) Then

Looks like there's a whole world there that I don't know about
Can't seem to find a list of HasValue and similar 'Natives' to Vb.Net in the help files
[In fact notNull and isEmpty are (confusingly) covered with examples in Help!]

OR intellisense so, if I type
If Not(RestaurantId.
HaveValue doesn't appear in the(all) list of possibilities


What I'm trying to do is Transform responses on a web page into a vb.net structure (trying to use a 'class' to do this)
Then have methods in the class which will write/read/edit the database
My first attempt at using classes! as you migh have guessed.

Patrice above has suggested using Linq or Entity Framework tools. I'll have a looksee.

Thanks again

Jim
 
A

Andrew Morton

Jim said:
OR intellisense so, if I type
If Not(RestaurantId.
HaveValue doesn't appear in the(all) list of possibilities

ICBW, but, tools->options->text editor->Basic->Auto list members/Hide
advanced members check box.

Andrew
 
J

Jim Bunton

Thanks again for your response to my posting Andrew.

Done the tools settings: *
[was already set - seems like it's the default]

Still get a limited list with intellisense not including 'HasValue': *
Have tried close Web Developer and restart.

Issue still the same [as above]

To note -
I am running the EXPRESS edition of Web Developer
* tried sending images .jpg of these but the message was rejected so I've cut them out.

Jim
 
G

Gregory A. Beamer

Thanks for your response to my posting Gregory.
I take your point about isnull(integervar) being inappropriate
I also found isEmpty() wasn't available

If Not (RestaurantId.HasValue) Then

Looks like there's a whole world there that I don't know about
Can't seem to find a list of HasValue and similar 'Natives' to Vb.Net
in the help files [In fact notNull and isEmpty are (confusingly)
covered with examples in Help!]


This is only valid with nullable types, which are declared, in VB, like
so:


Dim RestaurantId as Nullable(Of Integer)

You can then use the HasValue test on it.If you use a standard Integer,
it will fetter out like this:


Dim RestaurantId as Integer

Console.WriteLine(RestaurantId)

This will print 0, not Nothing or Null, as Integers are automatically
initialiazed. Strings will stay null however.

OR intellisense so, if I type
If Not(RestaurantId.
HaveValue doesn't appear in the(all) list of possibilities

Only with nullable types.
What I'm trying to do is Transform responses on a web page into a
vb.net structure (trying to use a 'class' to do this) Then have
methods in the class which will write/read/edit the database My first
attempt at using classes! as you migh have guessed.


Something like this:

Dim RestaurantIdString as String = Request("RestaurantId")

If Not(RestaurantId Is Nothing) Then
'Run code for restaurant
Else
'Run code indicating there is no restaurant with this id
End If

You can then turn the Restaurant Id into an integer, like so:

If Not (RestaurantId Is Nothing) Then
Dim RestaurantId as Integer

If(Int32.TryParse(RestaurantIdString, RestaurantId) Then
'Process ID
End If
End If

Patrice above has suggested using Linq or Entity Framework tools. I'll
have a looksee.

I think LINQ can solve a lot of problems, but if getting the Id off the
query string is the biggest issue, you still have to solve that.
Hopefully, I have given you some good pointers.
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top