I have a method which adds row to database (sql server 2005). Something is wrong with its because , when I have a row with UpdateDate 2000-12-31 23:59:59
it inserts 2001-01-01 00:00:00.000
. Is it possible? Culture of environment is polish if it is important. It's a magic for me :/
private void AddInvestmentStatus(InvestmentData.StatusyInwestycjiRow investmentStatusesRow)
{
SqlCommand cmd = new SqlCommand("AddInvestmentStatus");
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param1 = new SqlParameter("@InvestmentId", SqlDbType.BigInt);
param1.Value = investmentStatusesRow.InvestmentId;
cmd.Parameters.Add(param1);
cmd.Parameters.AddWithValue("@enumInvestmentStatusID", investmentStatusesRow.EnumInvestmentStatusID);
cmd.Parameters.AddWithValue("@modifiedBy", "System");
cmd.Parameters.AddWithValue("@UpdateDate", investmentStatusesRow.UpdateDate);
cmd.Parameters.AddWithValue("@ModifiedOn", investmentStatusesRow.ModifiedOn);
cmd.Parameters.AddWithValue("@dataVersion", investmentStatusesRow.DataVersion);
cmd.Connection = new SqlConnection(MyProgram.Properties.Settings.Default.ConnectionString);
if (cmd.Connection.State != ConnectionState.Open)
cmd.Connection.Open();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw;
}
}
}
create PROCEDURE [dbo].[AddInvestmentStatus]
@inwestmentID bigint,
@enumInvestmentStatusId bigint,
@updateDate datetime,
@dataVersion int,
@modifiedBy nvarchar(50),
@modifiedOn datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @investmentStatusesID bigint
INSERT INTO StatusyInwestycji(InwestycjaID)
VALUES (@inwestmentID)
SELECT @investmentStatusesID = SCOPE_IDENTITY();
INSERT INTO StatusyInwestycjiData(InvestmentStatusId, EnumStatusInwestycjiID,
UpdateDate, DataVersion, ModifiedBy, ModifiedOn)
VALUES (@investmentStatusesID, @enumInvestmentStatusId,
@updateDate, @dataVersion, @modifiedBy, @modifiedOn)
END
EDIT:
my date:
{2000-12-31 22:59:59}
Date: {2000-12-31 00:00:00}
Day: 31
DayOfWeek: Sunday
DayOfYear: 366
Hour: 22
Kind: Utc
Millisecond: 999
Minute: 59
Month: 12
Second: 59
Ticks: 631139003999990000
TimeOfDay: {22:59:59.9990000}
Year: 2000
SQL Server comes with the following data types for storing a date or a date/time value in the database: DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. SMALLDATETIME - format: YYYY-MM-DD HH:MI:SS.
Just use varchar and modify what you want in it without touch the time. In this example I use CONVERT(varchar(12), columnDatetime) to get a string with length of 12 characteres assuming a case of time with a format for example like "20:10:15.250".
The DATE data type was not introduced until SQL Server 2008. As a datatype, it is not part of 2005. You have to store it as a DATETIME and then use a conversion of some sort to strip the time part off. Also, SQL Server 2005 is no longer a supported platform.
Are you sure you're entering 23:59:59.000000 or are you entering 23:59:59.9999999?
SQL DateTime datatype has precision of 3.33ms (it will round to 0ms, 3ms, 7ms increments), meaning your 23:59:59.9999 will be rounded to 00:00:00.000000 of the next day.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With