By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,854 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,854 IT Pros & Developers. It's quick & easy.

TableAdapter returns null for stored proc returning a single value

P: n/a
Hi,

I have a stored procedure that returns a single value. Example:
[...]
SELECT @RowCount = COUNT(*) FROM t WHERE [...]
RETURN @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
Apr 8 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Have you set the SqlCommand.CommandType to StoredProcedure?

"bogdan" <bo****@company.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi,

I have a stored procedure that returns a single value. Example:
[...]
SELECT @RowCount = COUNT(*) FROM t WHERE [...]
RETURN @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


Apr 8 '08 #2

P: n/a
I used TableAdapter Qeury Configuration Wizard and selected "Use existing
stored procedure".

"Waldy" <so*****@microsoft.comwrote in message
news:OL**************@TK2MSFTNGP06.phx.gbl...
Have you set the SqlCommand.CommandType to StoredProcedure?

"bogdan" <bo****@company.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>Hi,

I have a stored procedure that returns a single value. Example:
[...]
SELECT @RowCount = COUNT(*) FROM t WHERE [...]
RETURN @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



Apr 8 '08 #3

P: n/a
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("@returnValue",SqlDbType.Int);
param.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
int rows = (int) cmd.Parameters("@returnValue").Value;
-- bruce (sqlwork.com)
"bogdan" wrote:
Hi,

I have a stored procedure that returns a single value. Example:
[...]
SELECT @RowCount = COUNT(*) FROM t WHERE [...]
RETURN @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
Apr 8 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.