Link to home
Start Free TrialLog in
Avatar of angireddy
angireddy

asked on

How to check for the datagrid datasource to be null

I have a datagrid which populates at runtime and then I use

dataView = ctype(datagrid.datasource, DataView)
if dataview.count = 0 then
.....

at "if...." I am getting null reference. How to check for the datasource is present or not.

Reddy

ASKER CERTIFIED SOLUTION
Avatar of james-ct16
james-ct16
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KGreg
KGreg

If NOT Datagrid.Datasource IS Nothing then

   ' The datasource is not null

ELSE

  ' The datasource is null

END IF



KGREG
I wouldn't use a try catch on this.  That could be a performance hit.  The best way is to check that the object is not "Nothing"

KGREG
Save the Try Blocks for "exceptional" cases.  If you can check for the condition very easily, do it - if not - then it should be caught.. like a server going down during a transaction, or a device failing, etc.

KGREG
Avatar of angireddy

ASKER

thankyou KREG, that was valuable information

reddy