SQL Server 2005中的一个问题:
我需要dd/mm/yyyy
格式的所有日期
SELECT
CONVERT(NCHAR(10), FromDate, 103) AS FromDate,
CONVERT(NCHAR(10), ToDate, 103) AS ToDate
FROM Tbl_PropertyRoomSeasonPrices
输出:
28/08/2012 | 09/01/2012
dd/mm/yyyy | mm/dd/yyyy
(CORRECT) (WRONG)
但fromDate为103,toDate为101,两者相同,为什么会有变化?
值保存如下:
的 BLL 的
public DateTime FromDate
{
get {return _fromDate;}
set{ _fromDate = value; }
}
public DateTime ToDate
{
get {return _toDate;}
set{ _toDate = value; }
}
public bool Save()
{
return _dalTbl_PropertyRoomSeasonPrices.Save();
}
的 DAL 的
public bool Save()
{
try
{
DataAccessLayerBaseClassDALBC=DataAccessLayerFactory.GetDataAccessLayer();
IDataParameter[]parameters=DALBC.CreateParameters(2);
parameters[0] = DALBC.CreateParameter("@FromDate", this._tbl_propertyroomseasonprices.FromDate);
parameters[1] = DALBC.CreateParameter("@ToDate", this._tbl_propertyroomseasonprices.ToDate);
DALBC.ExecuteScalar("spSave_Tbl_PropertyRoomSeasonPrices", CommandType.StoredProcedure, parameters);
}
catch (Exception ex)
{
return false;
}
return true;
}
的 SQL 的
ALTER PROCEDURE [dbo].[spSave_Tbl_PropertyRoomSeasonPrices]
(
@Id int,
@FromDate datetime = NULL,
@ToDate datetime = NULL
)
AS
DECLARE @count int
SET NOCOUNT ON
SELECT @count=COUNT(*) FROM Tbl_PropertyRoomSeasonPrices WHERE
[Id] = @Id
IF @count<=0 BEGIN
INSERT INTO [Tbl_PropertyRoomSeasonPrices]
(
[FromDate],
[ToDate]
)
VALUES
(
@FromDate,
@ToDate
)
SELECT @Id = SCOPE_IDENTITY();
END
ELSE BEGIN
UPDATE [Tbl_PropertyRoomSeasonPrices]
SET
[FromDate] = @FromDate,
[ToDate] = @ToDate
WHERE
[Id] = @Id
END
SELECT @Id