Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0DBNull.Value through the data layer.  ProblemsDBNull.Value through the data layer. Problems
Previous
 
Next
New Post
10/4/2007 11:23 AM
 

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

 
New Post
10/5/2007 11:37 AM
 

I would recommend that you declare the DateTime Value as a nullable type.  This allows you to set the value of birthday to null which will place a null in the database.  You can look up nullable types in the msdn documentation and it will show you how to declare and use them.  In the case of the DateTime value, unless you declare it as a nullable, you won't be able to set it equal to a null value.  Hopefully that all makes sense. 

 
New Post
10/5/2007 1:05 PM
 

Use the Null.NullDate helper method that returns the appropriate value. It's in the DotNetNuke.Common.Utilities namespace


Do you know the truth when you hear it?
Néstor Sánchez
The Dúnadan Raptor -->Follow Me on Twitter Now!
 
New Post
9/2/2009 12:38 PM
 

I've got a similar problem with strings. The user is allowed to leave a text box / string empty. In this case a NULL should be added to the database. Using Null.NullString still results in an empty string being written to the database. Any clues?

 

 
New Post
9/3/2009 3:32 AM
 

I've solved it with a check on an empty string (and conversion to NULL) in the SQL Server stored procedure.

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0DBNull.Value through the data layer.  ProblemsDBNull.Value through the data layer. Problems


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out