Solved

How to check for the datagrid datasource to be null

Posted on 2004-10-25
403 Views
Last Modified: 2008-02-01
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

0
Question by:angireddy
    5 Comments
     
    LVL 10

    Accepted Solution

    by:
    hi
    way i do it is with an additional if

    if not (dataview is nothing) then
    'data avaiable
    else
    'no data
    end if



    in addition to this you could as feel as an eliment of good form you could just catch teh error and handle it through the try catch statement

    regards

    james
    0
     
    LVL 6

    Expert Comment

    by:KGreg
    If NOT Datagrid.Datasource IS Nothing then

       ' The datasource is not null

    ELSE

      ' The datasource is null

    END IF



    KGREG
    0
     
    LVL 6

    Expert Comment

    by: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
    0
     
    LVL 6

    Expert Comment

    by: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
    0
     

    Author Comment

    by:angireddy
    thankyou KREG, that was valuable information

    reddy
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Product Review - Android Remix

    Come along for the ride with our Senior Product Manager, Brian Matis, as he reviews the Android Remix.

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now