.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

DateTime Null Or Minimum Value

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
Hello, I am working on a authentication system and I have the following: create table dbo.Users (   Id int identity not null,   LastLock datetime not null,   LastLogin datetime not null,   LastPasswordChange datetime not null,   LastReset datetime not null,   Username nvarchar(40) not null constraint Users_Username_U unique,     constraint Users_PK primary key clustered(Id) ) -- Users When a user opens the account there was never a login, it was never locked or password changed. So should I insert in this fields a Null value or a "SQL Minimum Date". What is your opinion in relation to this? Thanks, MiguelHello,I am working on a authentication system and I have the following:create table dbo.Users (  Id int identity not null,  LastLock datetime not null,  LastLogin datetime not null,  LastPasswordChange datetime not null,   LastReset datetime not null,  Username nvarchar(40) not null constraint Users_Username_U unique,    constraint Users_PK primary key clustered(Id)) -- UsersWhen a user opens the account there was never a login, it was never locked or password changed.So should I insert in this fields a Null value or a "SQL Minimum Date".What is your opinion in relation to this?What is the approach

View Complete Post

More Related Resource Links

Linq to SQL returns null for DateTime fields.


I have a linq to sql entity class in which I declared some DateTime fileds like this:

[Column(DbType = "smalldatetime")]
public DateTime? StartDate { get; set; }

And this is how I fetch data form repository:

return repository.Logs.OrderByDescending(l => l.LogID).FirstOrDefault();

All non DateTime fields are filled properly but all datetimes are null.

[Column(DbType = "smalldatetime")]

        public DateTime? StartDate { get; set; }

Showing the value as blank in a grid view when the Datetime field in SQL has its minimum value

Hi,Developing an application in C#.Retrieving data using SQL server. A record has a datetime field( eg: Resigned Date). If the datetime field in null in my code I will have the minimum value stored in the database which is "1/1/1900" ( eg: for current employees as they do not have a resigned date this field will have the 1/1/1900 value as I cannot leave this blank)Now when I'm displaying the employee records in a gridview in my application it shows the 1/1/1900 value for the "Resigned Date" field. I need this to be blank.Here is the code that I have done so far...void GetRecords(){DBConnect db = new DBConnect();DataSet ds = new DataSet();ds = db.getDataForgrid("Select * from Employee");DataTable dt = ds.Tables[0];GridView1.DataSource = dt;GridView1.DataBind();}Please help.Thanks

how to insert null or empty string to datetime var ?

hi i get data from xml file and sometime the date is empty. i have this code:     try { TimeTo = Convert.ToDateTime(R[15].ToString()); }         catch { TimeTo = null ; } but i got error because i cant insert null to datetime var what i can do ? thak's in advance

Insert null datetime into SQL DB


Hi There,

I have 2 textboxes for BEGINNING DATE and END DATE.
First I compare the dates so that the END DATE is bigger than the BEGINNING DATE. This is OK with the validators.

If the END DATE´S TEXTBOX is empty, then it should insert into the SQL DB, a null value. The field has a DATETIME type.
Since my INSERT Query requires a parameter when i call the ADD METHOD, it returns that the END DATE parameter is required.

Thank you.

How to format datetime & date with century?

Execute the following Microsoft SQL Server T-SQL datetime, date and time formatting scripts in Management Studio Query Editor to demonstrate the usage of the multitude of temporal data formats available and the application of date / datetime functions.


Essential SQL Server Date, Time and DateTime Functions

The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all.

datetime server



I'd like to have the date and time from server.

DateTime.Now Is ok?

Must be something else?


How to check for null/empty strings on dynamic objects?


What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:

if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)

If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?

Users getting logged out because HttpContext.Current is null


We've  been trying to fix this one for a couple years, and I'm just out of ideas, so any help is really appreciated!

We've got a fairly large, complex web application that uses Forms Authentication to authenticate users.  Throughout the application we store and retrieve information about users in the Session object, and in some cases in cookies.  In a couple places we check for the existence of the context, and if it's null we send the user back to the login page to re-establish the session. 

Just a quick run-down of this web app: C#, .NET 3.5, IIS 6, ASP.NET State Service to manage session

As for the session timer, we use our own home-grown timer, which is basically a client-side timer, which is backed up by a check to the SQL database to see when their last activity was.  This seems to work well for us.  It's not perfect, but it allows us to notify the user before the session times out, and allows us to be certain we're not logging a user out before their 60 minutes of inactivity is up.

What's happening is that certain users are being logged out after just a few minutes.  We've eliminated the timer as a cause and believe what's happening is the HttpContext.Current is null, so the user is logged out.  We do not know why the HttpContext.Current is null, and I underst

System.DateTime.AddDays: Value to add was out of range.


I'm getting the following error:

[ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value]
   System.DateTime.Add(Double value, Int32 scale) +7657639
   System.DateTime.AddDays(Double value) +19

The line from which this error originates has the following code:

expires = Now.AddDays(30)

It occurs irregularly and irreproducably. The server date/time is correct and set to GMT. I've heard that it could be some curiosity to do with timezones, but that is speculative.

It seems that we're some time from the year 10,000 yet, so I can't understand why adding thirty days to the current time could cause this! Any ideas? Culture settings perhaps?

'Value' should be between 'minimum' and 'maximum'.


I'm attempting to invoke with parameters:


Dim thing2 As New mydelsubPBStep(AddressOf pbStep)

Me.Invoke(thing2, "setMax", dt.Rows.Count)      <---- this is where the error occurs


the delegate looks like this:

Private Delegate

'element.className' is null or not an object



I just downloaded the project, compiled it and ran it right out of the box and when I put the mouse pointer over or remove the mouse pointer from either MenuItem in the menu demo, I generate this error:

'element.className' is null or not an object

It points to this javascript method:

updateClassName: function(operation, element, name, value) {
        this[operation + 'String'](
                function() {
                    return element.className;
                function(newValue) {
                    element.className = newValue;

Page.FindControl Causing Null Reference Exception


Hi guys,

I developed a page in VWD 2008 and it works perfectly locally, but when I deployed it on the server every Page.FindControl() call is causing the NullReference Exception "Object reference not set to an instance of an object. " Can anyone help me out? Code is below


Mike Marshall

            For i As Integer = 1 To 10
                If (CType(Page.FindControl("last_" & i), TextBox).Text.Length > 0) Or (CType(Page.FindControl("first_" & i), TextBox).Text.Length > 0) Or (CType(Page.FindControl("dob_" & i), TextBox).Text.Length > 0) Then
                    Dim person_entry(7) As String
                    person_entry(0) = info_list.Count - 1
                    person_entry(1) = CType(Page.FindControl("last_" & i), TextBox).Text
                    person_entry(2) = CType(Page.FindControl("first_" & i), TextBox).Text
                    person_entry(3) = CType(Page.FindControl("dob_" & i), TextBox).Text
                    person_entry(4) = CType(Page.FindControl("appear_" & i), TextBox).Text
                    person_entry(5) = CType(Page.FindControl("mental_" & i), TextBox).Text
                    person_entry(6) = CType(Page.FindControl("behave_" & i), TextB

linq and max, if return null return error


hi there
i have this query :

var result2 = (from TH in DB.Threshold
                          where TH.ProductSKUID == int.Parse(HID_ProductSKUID.Value)
                          select TH.ThresholdID).Max();

the problem is that if this query does not find any items, return null, so thow exception
how can i do to return 0??

ObjectDataSource CancelSelectOnNullParameter="false" // Select all when select parameter is null or


Hi ! I am using an objectdatasource in my project and I want to select all rows when the selectparameter value is empty ! I did the following but I am failling;
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="TugberkUgurluCom_TransferModule.TransferPriceDetailsAll" SelectMethod="GetAllDataFromPricesForControl" TypeName="TugberkUgurluCom_TransferModule.TransferPriceDBComponent" UpdateMethod="UpdateTransferPrices">
    <asp:ControlParameter ConvertEmptyStringToNull="true" ControlID="DropDownList1" Name="TpDestID" PropertyName="SelectedValue" Type="
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend