在一段代码中需要帮助 [英] need help in a piece of code

查看:60
本文介绍了在一段代码中需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

Hi all

Dim type As String
        Try
            Type = "select joindate from employee where emp_id='" & TextBox1.Text & "'"
            If Type > Type + 6 Then



当我执行此操作时,if条件如错误无法转换为double ..
请告诉问题.
我正在做的是我要加入日期,并检查它是否大于日期6个月..



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..

推荐答案

好吧,

类型是字符串.
然后将"select joindate from employee where emp_id=''" & TextBox1.Text & "''"分配给字符串本身.
然后您要检查Type是否为> 6.

6是一个数字,而不是字符串,并且在Type变量中有一个带文本的字符串,该文本不能与任何数字进行比较.

您应该首先执行要从中获取联接日期的数据库查询,并在从该查询中获取返回值之后,将其分配给应该与6比较的数字变量.

祝你好运!
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!


SELECT CASE WHEN(DATEDIFF(MM, JOINDATE, GETDATE()) > 6) THEN 1 ELSE O END AS IsQualified
FROM employee
WHERE ....


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



其中 GetValueFromDB 是一些接受输入Query并给出输出值的函数(所有sql功能都在内部处理),
monthDifference 是函数,当我们输入两个日期作为参数时,该函数将以月为单位返回差值

祝您编程愉快!
:)



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!
:)


这篇关于在一段代码中需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆