How to check the specific field in the row has contain null or value.

Posted by Venkat | Labels: , ,

Good Morning after a month I spend the time to post the small tips who already known but i would like to share this post which everyone come to know.

Question :  how to check the specific field in the row has contain null or value.

Normally we used to get the data from the DB using specific id for ex: get the specific user details using his userid. So it will return that row value. In that row some field may contain NULL value.

Here is the code to check the particular field contains value or null.

In my case I am getting the row from Database and assigned to the Datarow like this

Dim dr as DataRow

dr = ds.Tables(0).Rows(0)

Here the dr contains the row data from this I am checking the field.

Datarow  contains a method called  IsNull to check whether the field has null or value.

EX:

if (dr.IsNull("fieldname")) then
' if the field contain null do the manipulation here
else
' the field cotains some value.
End if 

the above code defines the Datarow contain a method called IsNull which is going to check the whether the specified fieldname has value or null as per we can manipulate it.

And also I am going to tell another tips which was pointed @ DotnetCurry.com here - thanks for that.

IE: if we are going to display user photo on Gridview where user have to upload his photo which will be an optional, User may or may not upload his photo, at that time the user who don't have photo on DB , the Gridview shows the cross mark image for that user. This is not good in practice from user point of view  instead we have to show the default image for the user who don't have photo on DB.

Example:

on the HTML img tag write like this

< img src="Dynamic-imagename" onerror="this.src='../images/NoImageFound.jpg'" .. / > 

This above tag will show the user photo who have photo on DB if there is no photo on DB for those it shows the default image specified on onerror event.

PayOffers.in