Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handling DB Nulls
Message
 
 
À
28/12/2009 15:24:03
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01440804
Message ID:
01440934
Vues:
42
Of course null should not be confused with Empty(). They mean two different things.

Have you really banished nulls from your database? There are times when a value truly is unknown, dates being a good example. I am more comfortable with calling the value null than using an arbitrary date such as 1900/01/01 to represent null.

>Hi Kevin,
>
>for a different (non-code, data-oriented) take on this issue: null should not be confused with empty(). So say the relational gurus, and I agree: if it should not be empty, then that could occur anytime a user changes a value, so whether the DB accepts a null or not is irrelevant at that point. So, what I do is provide a default for all fields that corresponds to an "empty" value. For dates I use "1900/01/01 12:00 AM" which if I am hitting it from VFP, will also yield empty(), fortuitously. In other words, while the columns are all set to NOT NULL, I never have a NULL value. And therefore never run into the problems requiring a workaround. It's been in production at a hundred sites or so for a couple of years with no issues.
>
>Hank
>
>>I'm reading the values off a dataset onto class properties:
>>
>>
>>public override void LoadData()
>>{
>>    DataSet ds = AppDataAccess.GetProjects(this.RecordId);
>>
>>    if (ds != null && ds.Tables.Count > 0)
>>    {
>>        _ProjectKey = (int)ds.Tables[0].Rows[0]["ProjectKey"];
>>        _ClientKey = (int)ds.Tables[0].Rows[0]["ClientKey"];
>>        _ProjectTypeKey = (int)ds.Tables[0].Rows[0]["ProjectTypeKey"];
>>        _RateTypeKey = (int)ds.Tables[0].Rows[0]["RateTypeKey"];
>>        _ProjectStatusKey = (int)ds.Tables[0].Rows[0]["ProjectStatusKey"];
>>        _PriorityKey = (int)ds.Tables[0].Rows[0]["PriorityKey"];
>>
>>        if (ds.Tables[0].Rows[0]["ManagerKey"] != DBNull.Value)
>>        {
>>            _ManagerKey = (int)ds.Tables[0].Rows[0]["ManagerKey"];
>>        }
>>
>>        _ProjectName = ds.Tables[0].Rows[0]["ProjectName"].ToString();
>>        _ProjectCode = ds.Tables[0].Rows[0]["ProjectCode"].ToString();
>>        _RateAmt = (float)ds.Tables[0].Rows[0]["RateAmt"];
>>        _EstHours = (float)ds.Tables[0].Rows[0]["EstHours"];
>>        _TotalHours = (float)ds.Tables[0].Rows[0]["TotalHours"];
>>        _EstStartDate = (DateTime)ds.Tables[0].Rows[0]["EstStartDate"];
>>        _EstEndDate = (DateTime)ds.Tables[0].Rows[0]["EstEndDate"];
>>        _ActualStartDate = (DateTime)ds.Tables[0].Rows[0]["ActualStartDate"];
>>        _ActualEndDate = (DateTime)ds.Tables[0].Rows[0]["ActualEndDate"];
>>        _PercentDone = (float)ds.Tables[0].Rows[0]["PercentDone"];
>>        _Comments = ds.Tables[0].Rows[0]["Comments"].ToString();
>>        _ProjectType = ds.Tables[0].Rows[0]["ProjectType"].ToString();
>>        _RateType = ds.Tables[0].Rows[0]["RateType"].ToString();
>>        _Status = ds.Tables[0].Rows[0]["Status"].ToString();
>>        _Priority = ds.Tables[0].Rows[0]["Priority"].ToString();
>>        _MgrFirstName = ds.Tables[0].Rows[0]["MgrFirstName"].ToString();
>>        _MgrLastName = ds.Tables[0].Rows[0]["MgrLastName"].ToString();
>>
>>    }
>>}
>>
>>
>>The problem is that I'm getting casting errors when there are DB nulls., Is there a better way of dealing with this other than the IF statement I used above? I don't want a bunch of IF's around each line above.
>>
>>Thanks
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform