473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

TableAdapter returns null for stored proc returning a single value

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
3 4978
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: CJM | last post by:
I frequently come across a small problem with my stored procedures; there are plenty of way around it, but I'm figuring that maybe my approach is subtly wrong. My typical code to call an Stored...
3
by: wackyphill | last post by:
Using ADO.NET Or regular queries on SQL Server, is there a good way of determining if a Stored Proc will be returning a result set or if it is a non-query that does all I/O through parameters? ...
4
by: Andrew Baker | last post by:
I have the following code that calles a stored proc in SQLServer. When the output parameter @custref is null (System.DBNull) I cant seem to find a test for this and I get an exception. I know I...
9
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
9
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio...
3
by: =?Utf-8?B?UmljaCBIdXRjaGlucw==?= | last post by:
I'm not really sure how to ask this question because I'm still getting my feet wet with data access and VB.NET, but here goes: To start off with, I'm using VB 2005 Express to connect to an Access...
2
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
1
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.