2014-04-23 3 views
0

ASP.NET 탭 컨테이너의 headertext 이미지를 다른 색상으로 변경해야합니다. 예를 들어, 오늘 23/04/2014이고 "FireTraffic"인 나의 탭 ImageUrl="~/icons/vwicn114.gif" 인 경우 2 일 안에 SQL Server에서 레코드를 업데이트해야하므로 ImageURL을 변경해야합니다. 그래서 그것을 TrafficLight 시스템으로 생각하십시오.2 개의 날짜를 비교하여 3 개의 결과를 제공합니다.

 connection.Open() 
    command = New SqlCommand("Select TOP 1 [Due Date] From FireTest Order By [Due Date] Desc", connection) 
    Dim DueDate As String = command.ExecuteScalar() 

    Dim Mycommand As New SqlCommand("Select TOP 1 [Date] From FireTest Order By [Date] Desc", connection) 
    Mycommand = command.ExecuteScalar() 

     connection.Close() 

그래서 내 코드가 될 것 같은 :

If mycommand "is 1 day more than" DueDate then firetraffic.ImageURL=Red 
    If mycommand "is 3 days or less than" DueDate then firetraffic.ImageURL=Yellow 
    End If 
    End If 
난 그냥 분명히 때로 믿을 공간에 넣어해야 모르는

'여기에 도움이되는 코드의 조각은 이해입니다 t 코드, 답변에 대한 안내는 크게 감사하겠습니다.

답변

1

이와 비슷한? :

Dim d1 As DateTime = DateTime.Now 
Dim dueDate As DateTime = ..... 

Dim result = "" 

'If overdue for one day or more' 
If (d1 - dueDate).Days >= 1 Then 
    result = "red" 
'If 3 days or more to due date' 
ElseIf (dueDate - d1).Days <= 3 Then 
    result = "yellow" 
Else : result = "green" 
End If 
+0

'String'및 'Date'유형에 '-'연산자가 정의되지 않았습니까? ... – Kallumasaurus

+1

"Date.Parse (dueDate)"또는 "CDate (dueDate)"를 사용하여 dueDate에 할당 할 값을 Date로 변환해야합니다. – GeoffWilson

관련 문제