views:

292

answers:

2

Hi,

I have a TableAdapter that is fetching rows from an Stored Procedure. For some reason, when there are no results, the TableAdapter returns an INT with value 0 instead of NULL. The SP has NOCOUNT ON.

The problem with this is that I have a ListView in the frontend with an EmptyDataTemplate, which is not being shown. When I ran the query in Query Analyzer, I see that it is returning 0 instead of NULL.

The SP has a simple 'SELECT * FROM WHERE ' with one INT parameter (NOT Output). Running it in Query Analyzer, I get no output, as expected.

Anybody know what's going on?!

+1  A: 

It looks like the stored procedure is returning the result. All stored procedure return a result code, it's most likely this.

John Nolan
Actually, I have verified that this is not the case. Running the query in Query Analyzer did not return any results, and similarly, running my other SPs which didn't have any results in the Dataset Designer did not result in this phantom result.
Wild Thing
If you take your stored procedure in Sql Server Management Studio and chose execute to new window it shows it reuturning an @rc. This is always 0 if the sproc runs and you don't change it. It may be coincidence.
John Nolan
Ok, you're right - it does. However, if this is the case will all SPs return 0 in the Dataset designer when they have no results? This doesn't seem to be happening.And what's really frustrating is that my ListView doesn't recognize that there are no results. Any thoughts on what might be happening?
Wild Thing
A: 

Check the ExcuteMode property of the tableAdapter for the query. Be sure it is set to "Reader". There are 3 options for ExecuteMode:

  1. Reader - Returns rows of data
  2. Scalar - Returns single value
  3. NonQuery - Returns an int with number of rows affected

Also check the Parameters Collection for a return value parameter. It should have properites AllowDBNull (true if you allow nulls), Direction (ReturnValue). This parameter should hold the results of your SP. In your example it would be null since there were no records returned.

Drell