我正在尝试获取日期,然后将其添加到数据库中。
为此,我正在使用(作为示例..)
If vDay = "TUESDAY" Or vDay = "2" Then
vDateEnd = DateTime.Now.AddDays(-2)
End If
然后我想将 vDateEnd 放入 SQL 中。如果我硬编码“2012 年 9 月 16 日”,它可以工作,但我玩过(正如您从注释掉的行中看到的那样)无济于事。
'report not found so we need to create one
'Create dates in the report if doe not exist
'### Update
Dim ConnectionString3 As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("mySQLConnectionString").ConnectionString
Dim dsNames3 As SqlDataSource
Dim sSQL3 As String
dsNames3 = New SqlDataSource
dsNames3.ConnectionString = sConnString
sSQL3 = "spWeeklyReportDatesCreate"
dsNames3.UpdateCommand = sSQL3
dsNames3.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure
dsNames3.UpdateParameters.Clear()
dsNames3.UpdateParameters.Add("DateStart", "09/16/2012")
'dsNames3.UpdateParameters.Add("DateEnd", "09/01/2013")
dsNames3.UpdateParameters.Add("DateEnd", (Mid(Date.Now.AddDays(-2), 1, 10)))
' dsNames3.UpdateParameters.Add("DateEnd", DateTime.Now.AddDays(-2).ToShortDateString("mm/dd/yyyy"))
dsNames3.UpdateParameters.Add("RunCompleted", "N")
dsNames3.Update()
dsNames3 = Nothing
存储过程
USE [db]
GO
/****** Object: StoredProcedure [dbo].[spWeeklyReportDatesCreate] Script Date: 16/09/2013 15:23:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spWeeklyReportDatesCreate]
@DateStart smalldatetime,
@DateEnd smalldatetime,
@RunCompleted nvarchar(1)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
INSERT INTO [tblweeklyreports]
(DateStart, DateEnd,RunCompleted)
VALUES
(@DateStart, @DateEnd,@RunCompleted)
--select @AnswerID=@@IDENTITY
END
Datebase - both set to 'datetime' at the moment though all of these parameters have been played with i.e. all SmallDate, DateTime, Date etc...