Hi,
I have the following stored procedure that does some processing and
puts the result in a temporary table. I tried several things that
procedure to display output that I can access with ADO.Net, but it
doesn't work. It doesn't even display the result in the query analyzer
unless I add SELECT @ReturnFullName
Any help?
The stored procedure:
CREATE PROCEDURE sp_SEARCH_MULTI PLE_NAMES @search4fatherO f
varchar(255), @maximum_father s int = 100, @ReturnFullName varchar(255)
Output
....
SELECT @ReturnFullName = name FROM #FULLNAME
------------------------------------------------
To Execute the stored procedure:
DECLARE @test varchar(255)
EXEC sp_SEARCH_MULTI PLE_NAMES @search4fathero f='مريم',
@returnfullname =@test
PRINT CONVERT(varchar (255), @test) 5 16559
On 22 May 2006 10:11:11 -0700, Wael wrote: Hi, I have the following stored procedure that does some processing and puts the result in a temporary table. I tried several things that procedure to display output that I can access with ADO.Net, but it doesn't work.
Hi Wael,
If you want to return a resultset to the client, just add a command such
as the one below in the appropriate place in your stored procedure:
SELECT Co11, Col2, ...
FROM #TempTable
-- WHERE ?????
This will expose the results of this query as a recordset to the client.
The stored procedure: CREATE PROCEDURE sp_SEARCH_MULTI PLE_NAMES @search4fatherO f varchar(255) , @maximum_father s int = 100, @ReturnFullName varchar(255) Output
Please choose a different name for your stored procedure. The "sp_"
prefix is reserved for Microsoft-supplied system stored procedures. If
you use this prefix for your own procedures, you will lose some
performance (because SQL Server will first try to find the procedure in
the master database), and yoou run the risk of unexpected effects if
Microsoft decides to use the same name for a system stored procedure
included in the next version, service pack or patch. ...
SELECT @ReturnFullName = name FROM #FULLNAME
If the #FULLNAME table holds more than one row, the effect of this
sttatement will be to assign the name from each of those rows in turn to
the variable, constantly replacing the "previous" value. Only the value
from the row that's processed last will stick. Since order of processing
of the rows is undefined, the net result of this statement will be to
waste some time and assign one "randomply chosen" name from the table to
@ReturnFullName . ------------------------------------------------ To Execute the stored procedure: DECLARE @test varchar(255) EXEC sp_SEARCH_MULTI PLE_NAMES @search4fathero f='????', @returnfullnam e=@test
You have to include the OUTPPUT keyword on the call as well:
EXEC sp_SEARCH_MULTI PLE_NAMES
@search4fatherO f = '????',
@ReturnFullName = @test OUTPUT
PRINT CONVERT(varchar (255), @test)
No need for the CONVERT - @test is already typed as varchar(255).
--
Hugo Kornelis, SQL Server MVP
Hi Hugo,
Thanks for your response. My ultimate goal is to return all the rows
not just one. Is that doable?
Also even with the select statement, the results are not accessible to
ADO.Net even though I can see them in the query analyzer.
THanks
Wael
Private Sub btnSearch_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnSearch.Click
Dim drParents As SqlDataReader
Dim cmdParents As New SqlCommand
Dim spParamenters As New SqlParameter
cnParents.Conne ctionString = Constants.Conne ctionString
cmdParents.Comm andType = CommandType.Sto redProcedure
cmdParents.Comm andText = "sp_SEARCH_MULT IPLE_NAMES"
spParamenters.P arameterName = "@search4father Of"
spParamenters.P arameterName = "@returnfullnam e"
cmdParents.Para meters("@search 4fatherOf").Val ue =
txtSearchParent .Text
cmdParents.Para meters("@return fullname").Valu e = "test"
spParamenters.S qlDbType = SqlDbType.VarCh ar
cmdParents.Para meters.Add(spPa ramenters)
cnParents.Open( )
cmdParents.Conn ection = cnParents
drParents = cmdParents.Exec uteReader
Response.Write( drParents.GetSt ring(0))
drParents.Close ()
End Sub
I have to give the output parameter a value otherwise it doesn't work.
Here is the error i get:
An SqlParameter with ParameterName '@search4father Of' is not contained
by this SqlParameterCol lection.
Before I used the parameters I used to get an error that there was no
data. I don't see why I should be using 'Output' since I have to use
the SELECT statement anyway.
Wael (se***@rocketma il.com) writes: Private Sub btnSearch_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnSearch.Click Dim drParents As SqlDataReader Dim cmdParents As New SqlCommand Dim spParamenters As New SqlParameter cnParents.Conne ctionString = Constants.Conne ctionString cmdParents.Comm andType = CommandType.Sto redProcedure cmdParents.Comm andText = "sp_SEARCH_MULT IPLE_NAMES" spParamenters.P arameterName = "@search4father Of" spParamenters.P arameterName = "@returnfullnam e" cmdParents.Para meters("@search 4fatherOf").Val ue = txtSearchParent .Text cmdParents.Para meters("@return fullname").Valu e = "test" ... I have to give the output parameter a value otherwise it doesn't work. Here is the error i get: An SqlParameter with ParameterName '@search4father Of' is not contained by this SqlParameterCol lection.
What it says. You have defined a parameter, set the name of it twice.
But you have never added it to the Parameters collection. To that end
you need to use the .Add method.
Apparently, you are very new to ADO .Net programming. Unfortunately,
newsgroups are not good venues for learning things from scratch, because
the answer will be small tidbits here and there. You are better off
trying to find some book with exercises and samples to get you going.
Or find some classes you can take in your area.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se
Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rowland Hills |
last post by:
I have a table which is returning inconsistent results when I query
it!
In query analyzer:
If I do "SELECT * FROM TABLE_NAME" I get no rows returned.
If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.
In Enterprise manager:
|
by: JB |
last post by:
To anyone that is able to help....
What I am trying to do is this. I have two tables (Orders, and
OrderDetails), and my question is on the order details. I would like
to set up a stored procedure that essentially inserts in the orders
table the mail order, and then insert multiple orderdetails within the
same transaction. I also need to do this via SQL 2000. Right now i
have "x" amount of variables for all columns in my orders tables,...
|
by: - |
last post by:
I have a country table with code and name columns and create a stored
procedure 'get_countries()' but have no idea what is the syntax to
return multiple rows.
I have searched the newsgroups and understand that the solution is to
use cursors. Searching for the mySQL solution is to no avail.
Do assist me with the syntaxt.
|
by: Stanley Sinclair |
last post by:
I have a need to return multiple result sets from a stored procedure.
Want that SP to call others to get the data.
Win2003, db2 8.1.5.
Can't figure out how to handle open cursors, and return >1 result
sets.
Thought about global temp tables.
|
by: Andrew |
last post by:
Hey all,
I am very new to ASP.Net (and .Net in general), but that isn't stopping the
boss from wanting to begin new projects in it. This latest project has me
kinda stumped and after a couple days of struggling, I figure asking you all
(the experts) will keep me from going down some dark and dangerous road.
The project I have is a fairly simple one, in theory anyway. The gist is to
create a page where the user enters an IDNumber,...
| |
by: jzogg7272 |
last post by:
In my code I am executing a stored procedure to do a single row insert.
I check the return value of the execution and I am getting -1, whereas
a few weeks ago it was returning 0. Actually, I found that all of my
insert stored procs are returning -1. The stored proc/insert statement
is still executing successfully but the return code is different. If I
execute the procedure from SQL Query Analyzer with the same params, it
shows a return...
|
by: bogdan |
last post by:
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
|
by: Constantine AI |
last post by:
Can anyone help?
Ive created the below stored procedure to allow an input parameter of post code to be entered to display properties which have this post code. The procedure creates fine but because i have two properties with the post code 'S1 4SG', the execution of the procedure fails, it gives the error:
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "CBRAID.PROC_PROPSEARCH", line 19...
|
by: codefragment |
last post by:
Hi
I have a chunky bit of sql that I will want to call from a number of
places. It will return a
few thousand rows. Whats the best way of structuring this?
1) I initially thought of using nested stored procedures and returning
the result in a temporary
table. However the scope of the temporary table seems to be limited to
the stored procedure
its created in so unless I create the temporary table in every stored
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |