473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to send null value to an Integer type variable?

Hello,
I have database field called 'PullAHead' defined as a bit field.
Now if user doesn't pick a 'Yes' or 'No' in the front I need to be able
to send a null value into the 'PullAHead' field in the database.

This is how I am trying to do it....

Dim PullAhead As Integer
PullAhead = Nothing
If _lblpullahead.Visible = True Then
PullAhead =
Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
End If

and finally I am sending the PullAhead integer variable to the
parameters list. But it is sending 0 (i.e I see False in the database
as its a bit field).

Could some one help me here how do I send a null value to the PullAHead
field?
Thanks
-L

Jul 27 '06 #1
4 2595
Learner,
Generally I use Boolean variables for Bit fields.

Starting with VS 2005 I normally use Nullable(Of T) for value types (such as
Integer & Boolean) that can contain Null.

Dim PullAhead As Nullable(Of Integer)
PullAhead = Nothing
If _lblpullahead.Visible = True Then
PullAhead = Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
End If

http://msdn2.microsoft.com/en-us/library/b3h38hb0.aspx

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Learner" <pr****@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
| Hello,
| I have database field called 'PullAHead' defined as a bit field.
| Now if user doesn't pick a 'Yes' or 'No' in the front I need to be able
| to send a null value into the 'PullAHead' field in the database.
|
| This is how I am trying to do it....
|
| Dim PullAhead As Integer
| PullAhead = Nothing
| If _lblpullahead.Visible = True Then
| PullAhead =
| Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
| End If
|
| and finally I am sending the PullAhead integer variable to the
| parameters list. But it is sending 0 (i.e I see False in the database
| as its a bit field).
|
| Could some one help me here how do I send a null value to the PullAHead
| field?
|
|
| Thanks
| -L
|
Jul 27 '06 #2
Hello Jay,
Thank you for the suggestion. Its a good one that I have learnt from
your posting today :) Now I am changing it to Boolean from integer as
you suggested.

So now the code looks like this

Dim PullAhead As Nullable(Of Boolean)
PullAhead = Nothing
If _lblpullahead.Visible = True Then
PullAhead = Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
End If
Hope full the above code snippet make sense I guess or else please do
post it one more time. And one more question it the line of code Dim
PullAhead As Nullable(Of Boolean)
we are already initializing it null (am I right here?) do you think I
still need to assign Nothing in the line of code PullAhead = Nothing?

Please bear with my english.

Thanks
-L

Jay B. Harlow [MVP - Outlook] wrote:
Learner,
Generally I use Boolean variables for Bit fields.

Starting with VS 2005 I normally use Nullable(Of T) for value types (such as
Integer & Boolean) that can contain Null.

Dim PullAhead As Nullable(Of Integer)
PullAhead = Nothing
If _lblpullahead.Visible = True Then
PullAhead = Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
End If

http://msdn2.microsoft.com/en-us/library/b3h38hb0.aspx

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Learner" <pr****@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
| Hello,
| I have database field called 'PullAHead' defined as a bit field.
| Now if user doesn't pick a 'Yes' or 'No' in the front I need to be able
| to send a null value into the 'PullAHead' field in the database.
|
| This is how I am trying to do it....
|
| Dim PullAhead As Integer
| PullAhead = Nothing
| If _lblpullahead.Visible = True Then
| PullAhead =
| Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
| End If
|
| and finally I am sending the PullAhead integer variable to the
| parameters list. But it is sending 0 (i.e I see False in the database
| as its a bit field).
|
| Could some one help me here how do I send a null value to the PullAHead
| field?
|
|
| Thanks
| -L
|
Jul 27 '06 #3
| we are already initializing it null (am I right here?) do you think I
| still need to assign Nothing in the line of code PullAhead = Nothing?
The compiler will implicitly initialize it to Nothing, you don't need to
assign Nothing to it per se...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Learner" <pr****@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
| Hello Jay,
| Thank you for the suggestion. Its a good one that I have learnt from
| your posting today :) Now I am changing it to Boolean from integer as
| you suggested.
|
| So now the code looks like this
|
| Dim PullAhead As Nullable(Of Boolean)
| PullAhead = Nothing
| If _lblpullahead.Visible = True Then
| PullAhead = Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
| End If
|
|
| Hope full the above code snippet make sense I guess or else please do
| post it one more time. And one more question it the line of code Dim
| PullAhead As Nullable(Of Boolean)
| we are already initializing it null (am I right here?) do you think I
| still need to assign Nothing in the line of code PullAhead = Nothing?
|
| Please bear with my english.
|
| Thanks
| -L
|
| Jay B. Harlow [MVP - Outlook] wrote:
| Learner,
| Generally I use Boolean variables for Bit fields.
| >
| Starting with VS 2005 I normally use Nullable(Of T) for value types
(such as
| Integer & Boolean) that can contain Null.
| >
| Dim PullAhead As Nullable(Of Integer)
| PullAhead = Nothing
| If _lblpullahead.Visible = True Then
| PullAhead = Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
| End If
| >
| http://msdn2.microsoft.com/en-us/library/b3h38hb0.aspx
| >
| --
| Hope this helps
| Jay B. Harlow [MVP - Outlook]
| .NET Application Architect, Enthusiast, & Evangelist
| T.S. Bradley - http://www.tsbradley.net
| >
| >
| "Learner" <pr****@gmail.comwrote in message
| news:11**********************@i3g2000cwc.googlegro ups.com...
| | Hello,
| | I have database field called 'PullAHead' defined as a bit field.
| | Now if user doesn't pick a 'Yes' or 'No' in the front I need to be
able
| | to send a null value into the 'PullAHead' field in the database.
| |
| | This is how I am trying to do it....
| |
| | Dim PullAhead As Integer
| | PullAhead = Nothing
| | If _lblpullahead.Visible = True Then
| | PullAhead =
| | Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
| | End If
| |
| | and finally I am sending the PullAhead integer variable to the
| | parameters list. But it is sending 0 (i.e I see False in the database
| | as its a bit field).
| |
| | Could some one help me here how do I send a null value to the
PullAHead
| | field?
| |
| |
| | Thanks
| | -L
| |
|
Jul 27 '06 #4
Hello Jay,
I tried with this but when I send this as a parameter to a method in
my Business Layer
its throwing this error

************************************************** *******************************************
System.InvalidOperationException was unhandled by user code
Message="Nullable object must have a value."
Source="mscorlib"
StackTrace:
at
System.ThrowHelper.ThrowInvalidOperationException( ExceptionResource
resource)
at System.Nullable`1.op_Explicit(Nullable`1 value)
at DealerQuestionsUS._btnGround_Click(Object sender, EventArgs
e) in
D:\VSProjects\GroundingDemo\GroundingDemo\DealerQu estionsUS.aspx.vb:line
143
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEven t(String
eventArgument)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection
postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
************************************************** ******************************************

Am I missing some thing here?
the code is exactly the same as we discussed in our previous postings.

Thanks
-L
Jay B. Harlow [MVP - Outlook] wrote:
| we are already initializing it null (am I right here?) do you think I
| still need to assign Nothing in the line of code PullAhead = Nothing?
The compiler will implicitly initialize it to Nothing, you don't need to
assign Nothing to it per se...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Learner" <pr****@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
| Hello Jay,
| Thank you for the suggestion. Its a good one that I have learnt from
| your posting today :) Now I am changing it to Boolean from integer as
| you suggested.
|
| So now the code looks like this
|
| Dim PullAhead As Nullable(Of Boolean)
| PullAhead = Nothing
| If _lblpullahead.Visible = True Then
| PullAhead = Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
| End If
|
|
| Hope full the above code snippet make sense I guess or else please do
| post it one more time. And one more question it the line of code Dim
| PullAhead As Nullable(Of Boolean)
| we are already initializing it null (am I right here?) do you think I
| still need to assign Nothing in the line of code PullAhead = Nothing?
|
| Please bear with my english.
|
| Thanks
| -L
|
| Jay B. Harlow [MVP - Outlook] wrote:
| Learner,
| Generally I use Boolean variables for Bit fields.
| >
| Starting with VS 2005 I normally use Nullable(Of T) for value types
(such as
| Integer & Boolean) that can contain Null.
| >
| Dim PullAhead As Nullable(Of Integer)
| PullAhead = Nothing
| If _lblpullahead.Visible = True Then
| PullAhead = Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
| End If
| >
| http://msdn2.microsoft.com/en-us/library/b3h38hb0.aspx
| >
| --
| Hope this helps
| Jay B. Harlow [MVP - Outlook]
| .NET Application Architect, Enthusiast, & Evangelist
| T.S. Bradley - http://www.tsbradley.net
| >
| >
| "Learner" <pr****@gmail.comwrote in message
| news:11**********************@i3g2000cwc.googlegro ups.com...
| | Hello,
| | I have database field called 'PullAHead' defined as a bit field.
| | Now if user doesn't pick a 'Yes' or 'No' in the front I need to be
able
| | to send a null value into the 'PullAHead' field in the database.
| |
| | This is how I am trying to do it....
| |
| | Dim PullAhead As Integer
| | PullAhead = Nothing
| | If _lblpullahead.Visible = True Then
| | PullAhead =
| | Convert.ToInt32(_drplPullAhead.SelectedValue.Trim)
| | End If
| |
| | and finally I am sending the PullAhead integer variable to the
| | parameters list. But it is sending 0 (i.e I see False in the database
| | as its a bit field).
| |
| | Could some one help me here how do I send a null value to the
PullAHead
| | field?
| |
| |
| | Thanks
| | -L
| |
|
Aug 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
3
by: sathyashrayan | last post by:
The standard confirms that the following initialization of a struct struct node { --- --- } struct node var = {NULL};
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
29
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's...
15
by: TC | last post by:
What does it mean for an integer to have a null value? I am trying to use the DataView.Find method. That method has an integer return type which contains the "index of the row in the DataView...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
5
by: BobRoyAce | last post by:
Let's say I have a table called Users which has a field DeptID which is an int. I also have a User class which has a method for getting the data for a particular user (i.e. User with specified ID)...
27
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1...
42
by: polas | last post by:
Afternoon all, I have some code (which I thought was OK, but now appreciate is probably not by the standard) which contains int a; ...... if (a==NULL) { ....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.