//这些是日期变量..如果你需要它们单独
Dim TodayDt As DateTime = DateTime.Today
Dim Tomorrow As DateTime = DateTime.Today.AddDays(1)
Dim TodayEnd as DateTime
TodayEnd = Tomorrow.AddSeconds(-1)
//这是在SQL Server中执行的SQL命令
SELECT
SUM(QTY) AS Discounts
FROM
dbo.fFinancialDataFull('Date Range Report', startdate , enddate, '1', '1', 'ALL', 'ALL', 'ALL', 'ALL', '1', '1', '1', '1', '1') AS fFinancialDataFull_1
WHERE ReportCategoryID = 62
AND startdate = TodayDt
AND enddate = TodayEnd AS unlimitedtbl
//这是你需要编写的函数,以使相同的 SQL 在 VB 上运行
Public Function GetValueByDates() As String
Dim TodayDt As DateTime = DateTime.Today
Dim Tomorrow As DateTime = DateTime.Today.AddDays(1)
Dim TodayEnd as DateTime
TodayEnd = Tomorrow.AddSeconds(-1)
Dim ReportCategoryID = 62
Dim sql As String = " SELECT
SUM(QTY) AS Discounts
FROM
dbo.fFinancialDataFull('Date Range Report', startdate , enddate, '1', '1', 'ALL', 'ALL', 'ALL', 'ALL', '1', '1', '1', '1', '1') AS fFinancialDataFull_1
WHERE ReportCategoryID = @ReportCategoryID
AND startdate = @TodayDt
AND enddate = @TodayEnd AS unlimitedtbl"
Using cn As New SqlConnection("Your connection string here"), _
cmd As New SqlCommand(sql, cn)
cmd.Parameters.Add("@TodayDt", SqlDbTypes.DateTime).Value = TodayDt
cmd.Parameters.Add("@TodayEnd", SqlDbTypes.DateTime).Value = TodayEnd
cmd.Parameters.Add("@ReportCategoryID", SqlDbTypes.int).Value = ReportCategoryID
Return cmd.ExecuteScalar().ToString()
End Using
End Function