Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a SQL Table that have a timestamp field.
https://pasteboard.co/JOFlRZh.png[^]
When i insert as new record to table (without time value) then inserting a time as "00:00:00".
https://pasteboard.co/JOFmoku.png[^]
What can i do for that?
Thanks.

What I have tried:

I have no idea. (This area must have more than 30 characters.)
Posted
Updated 16-Feb-21 9:25am
Comments
Richard MacCutchan 16-Feb-21 15:09pm    
What value would you expect to get from a zero time value?
gacar 16-Feb-21 15:13pm    
Time at recording time
Richard MacCutchan 16-Feb-21 15:20pm    
Then you need to add some code to set the item to the required time.
gacar 16-Feb-21 15:24pm    
Why? It is not necessary. If so why using timestamp?
Richard Deeming 17-Feb-21 6:46am    
The default value only applies if no value is specified when the record is inserted.

When you insert a record using Linq2Sql, it will specify a value for all columns that it knows about. If you haven't set a value for the property in your code, then the property value will be 00:00:00. That is the value which L2S will insert into the table, which means SQL Server will ignore the default constraint on the column.

Assuming you are using SQL Server, you can set the current date and time as in the example here: SQL DEFAULT Constraint[^]
OrderDate date DEFAULT GETDATE()
 
Share this answer
 
Comments
gacar 16-Feb-21 15:40pm    
Thank you for solution. I tired this but still inserting time as "00:00:00"
RickZeeland 16-Feb-21 15:44pm    
Then take a look at the answer by OriginalGriff, he suggests to pass a null value for the column, that should do the trick (don't know if this will work in Linq to SQL however)
gacar 16-Feb-21 15:49pm    
I already sending null value to SQL via linq. My problem this isue already. Don't fill time value auto by SQL
The easiest way is to set the default value for the column to GETDATE() and pass a null value for the column.

SQL will then put the current date and time into the field for you.
 
Share this answer
 
Comments
gacar 16-Feb-21 15:42pm    
Yes right, it must be so, but don't filling current time by SQL.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900