I am not a fan of the Typed Datasets, however sometimes you want to throw together a quick inventory or a CRUD interface, and I think thats where its existence is justified.
While working with the autogenerated typed datasets in ASP.NET (Ms Access) I came upon a problem with null values which I was ignoring for a while, finally I googled a bit to find the solution.
The Problem:
You will get the following exception if you are accessing a column value which could be null.
The value for column [ColumnName] in table [TableName] is DBNull
For example:
DB.CATEGORYDataTable tabCategory tabCategory = CATEGORIES.GetData();The Solution:
lblCategoryName.Text = tabCategory[0].CATEGORY_TITLE; //Exception thrown here
Use the autogenerated function Is[ColumnName]Null( ) to check the value prior to consumption.
For example:
lblCategoryName.Text = (tabCategory[0].Is CATEGORY_TITLENull()) ? "No value found": tabCategory[0]. CATEGORY_TITLE;Other Solutions:
http://stackoverflow.com/questions/4604414/best-way-to-check-if-a-data-table-has-a-null-value-in-it
Comments
Post a Comment