System.Nullable 2.0 Framework

  • Thread starter Thread starter Goofy
  • Start date Start date
G

Goofy

The 2.0 Framework has a new type called System.Nullable. This allows
something to Not exist, basically you can pass 'Nothing' to a method whose
parameters as System.Nullable.

Im looking at table adapters ; you know those clever little things which
allow you to contrsuct methods for manipulating data use this. So a method
might be declared someting like this.

Private Sub myMethod(ByVal myYear As System.Nullable(Of Integer), ByVal
myweek As System.Nullable(Of Integer))

End Sub

My question is. How to I translate this into a practical method call for a
value which may or may not exits. Lets say we have two text boxes.
yearTextBox and weekTextBox.

How to I assign an integer value or nothing depending on if the box is
emtpy, because you cant assign nothing to an integer. I dont want multiple
call lines to the one method, just one.
 
Goofy said:
The 2.0 Framework has a new type called System.Nullable. This allows
something to Not exist, basically you can pass 'Nothing' to a method whose
parameters as System.Nullable.

Im looking at table adapters ; you know those clever little things which
allow you to contrsuct methods for manipulating data use this. So a method
might be declared someting like this.

Private Sub myMethod(ByVal myYear As System.Nullable(Of Integer), ByVal
myweek As System.Nullable(Of Integer))

End Sub

My question is. How to I translate this into a practical method call for a
value which may or may not exits. Lets say we have two text boxes.
yearTextBox and weekTextBox.

How to I assign an integer value or nothing depending on if the box is
emtpy, because you cant assign nothing to an integer. I dont want multiple
call lines to the one method, just one.

I think that an object of type Nullable(Of Integer) can hold either an
integer value, or Nothing. To access the value of it use th Value
property. If you are worried about getting Nothing from it, use the
HasValue property which will tell you if the Nullable object stores a
value, or stores Nothing.

Inside your myMethod, you could say:

if myYear.HasValue then
myYearTextBox.text = myYear.Value
else
myYearTextBox.text = ""
end if
 
Well, thats doesent quite work because the sql where clause is like this.

WHERE ((week_no=@week_no) or (@week_no is null)) AND ( (pyear=@pyear) or
(@pyear is null) )


so the TableAdapterMethod needs to see either Nothing or a Value. So my
question is how do I call this on one line.
 
Back
Top