Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date field

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2010-07-13 : 10:14:37
Hi,

I am working with VB.NET 2005 and Sql server 2005.

I have a date field on my table called RECEIVEDDATE, this field is populated by a textbox within a datagridview on my form.

However, sometimes this field is empty and sql generates 01/01/1900, the next time a user opens the datagridview, the date 01/01/1900 appears instead of the blank space.

This is how I coded in VB.net before saving the cells from the datagridview. Could this be the root cause of the date set to 01/01/1900.

If e.ColumnIndex = 3 Then
DgvReturns.CommitEdit(DataGridViewDataErrorContexts.Commit)
Dim isChecked As Boolean = DirectCast(DgvReturns.Item(e.ColumnIndex, e.RowIndex).Value, Boolean)
If isChecked Then
DgvReturns.Item("PayStatus", e.RowIndex).Value = "No Pay"
DgvReturns.Item("ReceivedDate", e.RowIndex).Value = ""
Else
DgvReturns.Item("PayStatus", e.RowIndex).Value = ""
End If
End If



How can I go round this problem? Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-13 : 10:16:57
Try to save NULL value instead of empty string.
See this to understand
select
convert(datetime,''),
convert(datetime,NULL)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-13 : 10:37:12
I do not know much about it but this seems to be helpful:
http://www.c-sharpcorner.com/UploadFile/sd_patel/EnterNullValuesForDateTime11222005015742AM/EnterNullValuesForDateTime.aspx

There is an example for vb.net


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-16 : 11:43:17
Also refer this for more informations
http://beyondrelational.com/blogs/madhivanan/archive/2008/09/02/empty-string-and-default-values.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -