Does Dataset already exist

Mike_Stevens
Mike_Stevens used Ask the Experts™
on
is there any way to tell if a dataset already exists or has been created?  Something like:

ds = dataset

If ds.exists = true then
....
elseif ds.exists = false then
....
End if

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shaun KlineLead Software Engineer

Commented:
If your object equates to nothing (ds Is Nothing) then it has not been created. If you need to know if the object has been filled, you can check if the dataset contains any tables, and that the tables have rows.
Top Expert 2015
Commented:
If ds IsNot Nothing Then
   'DataSet has not been created (New was not called)
Else
   If ds.Tables.Count=0 then
      'The DataSet has been created but is empty
   Else
      'The DataSet has been created and contains at least one table
   End If
End If

This being said, do not make the mistake we encounter all over the Internet. If you have only one table, or if you do not use DataRelation objects to create relations between many tables, you do not need a DataSet. It just adds extra overhead. A DataTable object is sufficient in such a case.

Author

Commented:
Excellent help by both!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start Today