Click here to Skip to main content
15,909,530 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi all ,
i have radio button
with 2 values 1,0 yes or no
if user choose no
i have to object elments their values should be null
one of them is datetime
rational_obj.OfficeWorkApproveDate =nothing
and the other one is string
how can i put them to null in vb.net
?
Posted
Comments
Not clear. What is the issue?

1 solution

If it's a string, you can just set it to Nothing, because String is a reference type.
VB.NET
yourString = Nothing

But for a value type (and DateTime is one), Nothing gives it the equivalent to default(T) in C#, and for DateTime, this is DateTime.MinValue. If you want to set it to Nothing, make OfficeWorkApproveDate a nullable type[^] (so when you create the variable, add a question mark after the variable name).
Then you can give it the Nothing value:
VB.NET
rational_obj.OfficeWorkApproveDate = Nothing

And later, if you want to test whether it has a value, try this:
VB.NET
If rational_obj.OfficeWorkApproveDate.HasValue Then
    Dim approveDate As DateTime = rational_obj.OfficeWordApproveDate.Value
    ' do operations with approveDate
Else
    ' it does not have a value
End If
 
Share this answer
 
v2
Comments
fady_hasnaa 26-Oct-14 16:14pm    
when puting rational_obj.OfficeWordApproveDate=DateTime.MinValue
in inserting to db it will be like this
INSERT INTO RationaleSystemicTbl
(SchID ,InsuranceOrderNO, InsuranceEDate, InsuranceNoOfSubscribeSToutorial, InsuranceNoOfSubscribeNSToutorial,InsuranceNoOfSubscribeSAdimistrator, InsuranceNoOfSubscribeNSAdimistrator, InsuranceNoOfSubscribeSUsers, InsuranceNoOfSubscribeNSUsers, JoinFilledSchoolDate, AmanahApprove, AmanaApproveDate, FileNoInOfficeWork, OfficeWorkApprove, AlzakahEDate, OfficeWorkApproveDate, TaesheeratTotal, TaesheeratUse, TaesheeratUnUse,Amanah_approve_num,Office_work_approve_num,non_sa_on_kfalah)
VALUES(N'1988',3249423,CONVERT(VARCHAR(10),'10/8/2014', 111) , 16, 16, 19,7, 18, 18, CONVERT(VARCHAR(10),'9/25/2014', 111) , 0, CONVERT(VARCHAR(10),'12:00:00 AM', 111) , 03293232,null , CONVERT(VARCHAR(10),'10/29/2014', 111) , CONVERT(VARCHAR(10),'12:00:00 ', 111) ,null , 17, 16, 14,null,17)
---------------
CONVERT(VARCHAR(10),'12:00:00 ', 111) and the column is datetime will not accept string how can i fix it ?
as i can not put it to nullable as sometimes it has value
Thomas Daniels 27-Oct-14 3:29am    
Use the if-else statement I provided in my answer, and if your nullable has a value, put that value in your SQL query, and if it does not have a value, put null in your SQL query (SQL supports null for datetime).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900