คือผมอยากจะคำนวนจำนวนวันที่เหลืออยู่ยังไงครับ From ดังนี้
*เอาวันที่ใน lblDue มาคำนวนแล้วไปแสดงที่ Label1
โค้ดที่ผมเขียน
Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Public Class UploadImage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ShowDataInfo()
End Sub
Protected Sub ShowDataInfo()
Dim objConn As SqlConnection
Dim strConnString As String
Dim strSQL As StringBuilder
Dim objCmd As SqlCommand
Dim dtReader As SqlDataReader
'*** Open Connection ***'
strConnString = "Data Source=WDB-PR0168\SQLEXPRESS;Initial Catalog=ESD_001;Integrated Security=True"
objConn = New SqlConnection
objConn.ConnectionString = strConnString
objConn.Open()
'*** Get Data ***'
strSQL = New StringBuilder
strSQL.Append(" SELECT * FROM Tools_ESD ")
strSQL.Append(" WHERE WD_Tag = @sWD_Tag ")
objCmd = New SqlCommand(strSQL.ToString(), objConn)
objCmd.Parameters.Add("@sWD_Tag", SqlDbType.VarChar).Value = TextBox1.Text
dtReader = objCmd.ExecuteReader()
If dtReader.HasRows Then
dtReader.Read()
Me.lblName.Text = dtReader("Eqiument").ToString()
Me.lblTag.Text = dtReader("WD_Tag").ToString()
Me.lblDue.Text = dtReader("Due_Date").ToString()
End If
dtReader.Close()
objConn.Close()
objConn = Nothing
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
ShowDataInfo()
End Sub
End Class
SELECT DATEDIFF(day,'2014-08-05','2014-06-05') AS DiffDate
syntax
DATEDIFF ( datepart , startdate , enddate )
datepart
Datepart Abbreviations
Year = yy, yyyy
quarter = qq, q
Month = mm, m
dayofyear = dy, y
Day = dd, d
Week = wk, ww
Hour = hh
minute = mi, n
second = ss, s
millisecond = ms
Imports System.Data
Imports System.Data.SqlClient
Public Class UploadImage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ShowDataInfo()
End Sub
Protected Sub ShowDataInfo()
Dim objConn As SqlConnection
Dim strConnString As String
Dim strSQL As StringBuilder
Dim objCmd As SqlCommand
Dim dtReader As SqlDataReader
'*** Open Connection ***'
strConnString = "Data Source=WDB-PR0168\SQLEXPRESS;Initial Catalog=ESD_001;Integrated Security=True"
objConn = New SqlConnection
objConn.ConnectionString = strConnString
objConn.Open()
'*** Get Data ***'
strSQL = New StringBuilder
strSQL.Append(" SELECT * FROM Tools_ESD ")
strSQL.Append(" WHERE WD_Tag = @sWD_Tag ")
objCmd = New SqlCommand(strSQL.ToString(), objConn)
objCmd.Parameters.Add("@sWD_Tag", SqlDbType.VarChar).Value = TextBox1.Text
dtReader = objCmd.ExecuteReader()
If dtReader.HasRows Then
dtReader.Read()
Me.lblName.Text = dtReader("Eqiument").ToString()
Me.lblTag.Text = dtReader("WD_Tag").ToString()
Me.lblDue.Text = dtReader("Due_Date").ToString()
End If
dtReader.Close()
objConn.Close()
objConn = Nothing
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
ShowDataInfo()
End Sub
End Class