I have a birthday field in a database and am trying to allow them to not type in anything.. I have allowed null values in the SQL data.. here is the relevant code. This does not work cause it says the dbnull.value can not be converted to date. I get an error if i try birthday = "" also (cant convert "" to date). If i try to assign "1/1/0001" it errors giving me that must be between Must be between 1/1/1753 and blah blah blah. if i set at 1/1/1753.. it actually dispays that value everywhere and i will get endless complaints about that not really being their birthday. Any good tricks out there to do this?
My VB minus a bunch of extra fields you dont care about
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim objPeoples As New PeopleController
Dim colPeoples As List(Of PeopleInfo)
colPeoples = objPeoples.GetPeoples(ModuleId)
If colPeoples.Count = 0 Then
Dim objPeople As PeopleInfo = New PeopleInfo
objPeople.ModuleId = ModuleId
objPeople.Family_ID = 0
objPeople.First_Name = ""
objPeople.Birthday = DBNull.Value (-- ERROR-- can not be converted to date--)
People Controller
Public Function GetPeoples(ByVal ModuleId As Integer) As List(Of PeopleInfo)
Return CBO.FillCollection(Of PeopleInfo)(DataProvider.Instance().GetPeoples(ModuleId))
End Function
Data Provider
Public MustOverride Function GetPeoples(ByVal ModuleId As Integer) As IDataReader
SQL DataProvider
Public Overrides Function GetPeoples(ByVal ModuleId As Integer) As IDataReader
Return CType(SqlHelper.ExecuteReader(ConnectionString, GetFullyQualifiedName("GetPeoples"), ModuleId), IDataReader)
End Function
Stored Proceedure is boring dont think you need it.. gets all fields passing the module ID
SQL Table Birthday field type is DateTime, Allows Nulls