Dataset empty or is nothing?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Excerpt from Code:

dim ds as new dataset

ds= execute("Stored_Proc")
dim name as string= ds.tables(0).datasetname

execute is a function that executes the stored procedure Stored_Proc.

Suppose execute returns an empty dataset, what kind of exception is raised?
 
Asume the "execute()" function returns an empty DataSet
(DataSet.Tables.Count=0), the next line of code

dim name as string= ds.tables(0).datasetname

will always raise exception, because DataTable does not have a property
called "datasetname" (it has property called "TableName").

Maybe it is your typo and you meant "TableName". If so, that line of code
will raise "Object reference not set...." exception, because "Tables[0]"
does not exist.
 
As others have noted, there is no "datasetname" property.
However, there are two situations that you need to be ready for.
1) The query returns no rows. In this case you'll get a new DataTable but
the Rows.Count property will be 0.
2) The query returns no rowset. If you execute an action query or the SP
executes logic that bypasses the SELECT, you will get a resultset, but no
rowset. In this case the DataTable will not be created at all.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top