|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to send null value to an Integer type variable?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 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 -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Learner" <pra***@gmail.com> wrote in message news:1154029132.412020.299990@i3g2000cwc.googlegroups.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 | 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: Show quoteHide quote > 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" <pra***@gmail.com> wrote in message > news:1154029132.412020.299990@i3g2000cwc.googlegroups.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 > | | we are already initializing it null (am I right here?) do you think I The compiler will implicitly initialize it to Nothing, you don't need to | still need to assign Nothing in the line of code PullAhead = Nothing? assign Nothing to it per se... -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Learner" <pra***@gmail.com> wrote in message news:1154038677.185627.217870@m79g2000cwm.googlegroups.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" <pra***@gmail.com> wrote in message | > news:1154029132.412020.299990@i3g2000cwc.googlegroups.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 | > | | 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\DealerQuestionsUS.aspx.vb:line 143 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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: Show quoteHide quote > | 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" <pra***@gmail.com> wrote in message > news:1154038677.185627.217870@m79g2000cwm.googlegroups.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" <pra***@gmail.com> wrote in message > | > news:1154029132.412020.299990@i3g2000cwc.googlegroups.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 > | > | > | |
|||||||||||||||||||||||