Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Explain code "System.Nullable(Of Integer)"...

Status
Not open for further replies.

sqlsamurai

Programmer
May 11, 2005
120
US
I was messing around with the datasources window, I drug a stored procedure from there onto a form and a lot of stuff created itself automatically.

Here is my question. The Fill method on the TableAdapter looks like this:

fill.jpg


and the code created looks like this:

Code:
Me.STI50TempTagsTableAdapter.Fill(Me.STI2DataSet.STI50TempTags, New System.Nullable(Of Integer)(CType(PurchaseOrderIDToolStripTextBox.Text, Integer)), 

New System.Nullable(Of Integer)(CType(ProductionIDToolStripTextBox.Text, Integer)),
 
New System.Nullable(Of Integer)(CType(ReturnIDToolStripTextBox.Text, Integer)))

What is this System.Nullable(Of Integer)? How does it work? And what is the significance of them creating a new system.nullable of type integer and then using ctype on the text box? There is a lot going on in-line and I'd like some help decifering it.

THanks
 
Is this in 2005? I've never seen that code in 2k2 but my guess would be that ParmName as system.nullable(of integer) is an integer parameter that can accept a null value.

This:
Code:
New System.Nullable(Of Integer)(CType(ProductionIDToolStripTextBox.Text, Integer))

casts the value of the textbox to an integer, and I'm guessing that if the textbox is empty, the integer is set to null instead of zero.

Null functionality for primative types, a pretty nice tool, albeit a bit wordy. I would probably be easier to create a function to do the work for you:
Code:
private function MakeNullable(value as string)
  return New System.Nullable(Of Integer)(CType(value, Integer))
end function

Then you could call the method with MakeNullable(ProductionIDToolStripTextBox.Text)

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top