Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi all
 
Dim type As String
        Try
            Type = "select joindate from employee where emp_id='" & TextBox1.Text & "'"
            If Type > Type + 6 Then
 
when i am executing this the if condition giving error like can't convert to double..
please tell the problem.
what i am doing is i m taking the joining date and checking it is greater then 6 months from date or not..
Posted 25-Sep-12 0:18am
Comments
JF2015 at 25-Sep-12 6:24am
   
This code doesn't make sense - what do you want to achieve?
snehasish nandy at 25-Sep-12 6:39am
   
i want a condition where if the joindate crosses more then 6 months then i have to enable and disable some option...
i am fetching the joining date from database
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well,
 
Type is a string.
Then you assign "select joindate from employee where emp_id='" & TextBox1.Text & "'" to the string itself.
And then you are checking if Type is > 6.
 
6 is a number, not a string, and inside the Type variable you have a string with text, which can't be compared to any number.
 
You should first execute the database query from which you want to get the joindate and after getting the return value from that query, assign it to a numeric variable that you should compare to the 6.
 
Good luck!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

SELECT CASE WHEN(DATEDIFF(MM, JOINDATE, GETDATE()) > 6) THEN 1 ELSE O END AS IsQualified
FROM employee
WHERE ....
  Permalink  
Comments
snehasish nandy at 25-Sep-12 6:29am
   
what is IsQualified..???
Kuthuparakkal at 25-Sep-12 6:32am
   
u change it to anything... upto you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Dim Dt As DateTime
        Try
            Dt = GetValueFromDB("select joindate from employee where emp_id='" & TextBox1.Text & "'")
            'To Access Month
            if monthDifference(Dt,system.DateTime.Date) > 6 then
               'Enable -disable controls as your requirement
            End if
Public Function monthDifference(ByVal startDate As DateTime, ByVal endDate As DateTime) As Integer
    Dim t As TimeSpan = endDate - startDate
    Dim difference As Integer = t.Days
    Dim months As Integer = Math.Floor(difference / 30.475)
    Return months
End Function
 
where GetValueFromDB is some function that takes input Query and gives Output value (all sql functionality are handled inside) ,
and monthDifference is function that will return difference in months when we input two dates as parameter
 
Happy coding!
Smile | :)
  Permalink  
v2
Comments
snehasish nandy at 25-Sep-12 6:37am
   
what i have to do is if the joining date is greater then 6 months then i have to enable and disable few options..
e.g. if joining>joining+6 then
a.enable=false
end if
please tell me this condition..
aarti meswania at 25-Sep-12 6:54am
   
use this function for getting difference between months
 
Public Function monthDifference(ByVal startDate As DateTime, ByVal endDate As DateTime) As Integer
Dim t As TimeSpan = endDate - startDate
Dim difference As Integer = t.Days
Dim months As Integer = Math.Floor(difference / 30.475)
Return months
 
End Function

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



Advertise | Privacy | Mobile
Web04 | 2.8.140826.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100