TableAdapter returns null for stored proc returning a single value

Hi,

I have a stored procedure that returns a single value. Example:
[...]
SELECT [at] RowCount = COUNT(*) FROM t WHERE [...]
RETURN [at] RowCount

I created a data set, table adapter, and adapter's method configured for the
stored proc and as returning a single value. The wizard created an adapter
method that calls SqlCommand.ExecuteScalar(). The problem is that
ExecuteScalar() always returns a null object. I have no problem executing
the stored procedure from outside of asp.net.

Could someone please let me give me some idea what could be wrong here?

Thanks,
Bogdan
bogdan [ Di, 08 April 2008 16:12 ] [ ID #1937756 ]

Re: TableAdapter returns null for stored proc returning a single value

Have you set the SqlCommand.CommandType to StoredProcedure?

"bogdan" <bogdan [at] company.com> wrote in message
news:%23vIBPKYmIHA.1208 [at] TK2MSFTNGP05.phx.gbl...
> Hi,
>
> I have a stored procedure that returns a single value. Example:
> [...]
> SELECT [at] RowCount = COUNT(*) FROM t WHERE [...]
> RETURN [at] RowCount
>
> I created a data set, table adapter, and adapter's method configured for
> the stored proc and as returning a single value. The wizard created an
> adapter method that calls SqlCommand.ExecuteScalar(). The problem is that
> ExecuteScalar() always returns a null object. I have no problem executing
> the stored procedure from outside of asp.net.
>
> Could someone please let me give me some idea what could be wrong here?
>
> Thanks,
> Bogdan
>
>
John Smith [ Di, 08 April 2008 16:27 ] [ ID #1937761 ]

Re: TableAdapter returns null for stored proc returning a single value

I used TableAdapter Qeury Configuration Wizard and selected "Use existing
stored procedure".

"Waldy" <someone [at] microsoft.com> wrote in message
news:OL5XhSYmIHA.3780 [at] TK2MSFTNGP06.phx.gbl...
> Have you set the SqlCommand.CommandType to StoredProcedure?
>
> "bogdan" <bogdan [at] company.com> wrote in message
> news:%23vIBPKYmIHA.1208 [at] TK2MSFTNGP05.phx.gbl...
>> Hi,
>>
>> I have a stored procedure that returns a single value. Example:
>> [...]
>> SELECT [at] RowCount = COUNT(*) FROM t WHERE [...]
>> RETURN [at] RowCount
>>
>> I created a data set, table adapter, and adapter's method configured for
>> the stored proc and as returning a single value. The wizard created an
>> adapter method that calls SqlCommand.ExecuteScalar(). The problem is
>> that ExecuteScalar() always returns a null object. I have no problem
>> executing the stored procedure from outside of asp.net.
>>
>> Could someone please let me give me some idea what could be wrong here?
>>
>> Thanks,
>> Bogdan
>>
>>
>
>
bogdan [ Di, 08 April 2008 16:34 ] [ ID #1937763 ]

RE: TableAdapter returns null for stored proc returning a single value

executescaler returns the first column, of the first row, of the first
resultset. your stored proc does not return any rows, only a return value. to
get the return value, use ExecuteNonQuery with a returnvalue parameter

cmd.CommandText = "myproc";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter(" [at] returnValue",SqlDbType.Int);
param.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
int rows = (int) cmd.Parameters(" [at] returnValue").Value;


-- bruce (sqlwork.com)


"bogdan" wrote:

> Hi,
>
> I have a stored procedure that returns a single value. Example:
> [...]
> SELECT [at] RowCount = COUNT(*) FROM t WHERE [...]
> RETURN [at] RowCount
>
> I created a data set, table adapter, and adapter's method configured for the
> stored proc and as returning a single value. The wizard created an adapter
> method that calls SqlCommand.ExecuteScalar(). The problem is that
> ExecuteScalar() always returns a null object. I have no problem executing
> the stored procedure from outside of asp.net.
>
> Could someone please let me give me some idea what could be wrong here?
>
> Thanks,
> Bogdan
>
>
>
brucebarker [ Di, 08 April 2008 17:10 ] [ ID #1937775 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » TableAdapter returns null for stored proc returning a single value

Vorheriges Thema: Q: Login Control is behaving strange when site on prod server.
Nächstes Thema: browser back and events