473,396 Members | 2,002 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,396 software developers and data experts.

Beginner stored proc issue

bic
I need to call a sp that inserts a row and returns the id. I take it that I
have to use command vs. reader sqlcleint object to achieve this? How'd I
read the id back if the id is returded via a select at the end of the SP vs.
thru a o/p parameter? Thanks.
--
bic
Jul 17 '06 #1
4 901
I made that once like this:

Create Procedure sp_myproc
@name as varchar(100)
as
begin
insert into table (name) values (@name)
select @@identity --assuming that id is identity
end

In your .Net code, you declare a commandType of scalar a get the return of
the stored procedure after execute it.

I hope this helps you.

"bic" <bi*@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
>I need to call a sp that inserts a row and returns the id. I take it that
I
have to use command vs. reader sqlcleint object to achieve this? How'd I
read the id back if the id is returded via a select at the end of the SP
vs.
thru a o/p parameter? Thanks.
--
bic

Jul 17 '06 #2
bic
Hi,

How come when I tried to read the sqlCommand sCMD and found it to be -1
after exec and 0 before exec? Thanks.
--
bic
"Vitor Alcântara Batista" wrote:
I made that once like this:

Create Procedure sp_myproc
@name as varchar(100)
as
begin
insert into table (name) values (@name)
select @@identity --assuming that id is identity
end

In your .Net code, you declare a commandType of scalar a get the return of
the stored procedure after execute it.

I hope this helps you.

"bic" <bi*@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
I need to call a sp that inserts a row and returns the id. I take it that
I
have to use command vs. reader sqlcleint object to achieve this? How'd I
read the id back if the id is returded via a select at the end of the SP
vs.
thru a o/p parameter? Thanks.
--
bic


Jul 17 '06 #3
With the example given below, you'd need to return the identity via:

object o = sCMD.ExecuteScalar()

Is that what you're doing?
"bic" <bi*@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
Hi,

How come when I tried to read the sqlCommand sCMD and found it to be -1
after exec and 0 before exec? Thanks.
--
bic
"Vitor Alcântara Batista" wrote:
>I made that once like this:

Create Procedure sp_myproc
@name as varchar(100)
as
begin
insert into table (name) values (@name)
select @@identity --assuming that id is identity
end

In your .Net code, you declare a commandType of scalar a get the return
of
the stored procedure after execute it.

I hope this helps you.

"bic" <bi*@discussions.microsoft.comwrote in message
news:25**********************************@microso ft.com...
>I need to call a sp that inserts a row and returns the id. I take it
that
I
have to use command vs. reader sqlcleint object to achieve this? How'd
I
read the id back if the id is returded via a select at the end of the
SP
vs.
thru a o/p parameter? Thanks.
--
bic



Jul 18 '06 #4
bic
Thanks very much , Brendan and Victor.
--
bic
"Brendan Green" wrote:
With the example given below, you'd need to return the identity via:

object o = sCMD.ExecuteScalar()

Is that what you're doing?
"bic" <bi*@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
Hi,

How come when I tried to read the sqlCommand sCMD and found it to be -1
after exec and 0 before exec? Thanks.
--
bic
"Vitor Alcântara Batista" wrote:
I made that once like this:

Create Procedure sp_myproc
@name as varchar(100)
as
begin
insert into table (name) values (@name)
select @@identity --assuming that id is identity
end

In your .Net code, you declare a commandType of scalar a get the return
of
the stored procedure after execute it.

I hope this helps you.

"bic" <bi*@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
I need to call a sp that inserts a row and returns the id. I take it
that
I
have to use command vs. reader sqlcleint object to achieve this? How'd
I
read the id back if the id is returded via a select at the end of the
SP
vs.
thru a o/p parameter? Thanks.
--
bic


Jul 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Wolfgang Kreuzer | last post by:
Try hard to become familiar with T-SQL. Can anybodey tell me the best way to deal with set's provided by a stored procedure. Til yesterday I thougt trapping set in temp table using INSERT EXEC...
2
by: Mike Hutton | last post by:
I have a rather odd problem. I have a SP which uses temp. tables along the way, and then returns a table of results: CREATE PROCEDURE dbo.usp_myproc( @pNameList VARCHAR(6000) ) AS
12
by: Jason Huang | last post by:
Hi, In my C# Windows Form application project, I have done all queries on my codes. Now I wanna try using the Stored Procedure. But I am not clear about why using the stored procedure. Would...
3
by: mandible | last post by:
I'm trying to call one stored procedure inside another. I was wondering if this is possible Some ideas I was toying with is putting the first stored procedure inside of a temp table but haven't...
0
by: mirandacascade | last post by:
Questions toward the bottom of the post. Situation is this: 1) Access 97 2) SQL Server 2000 3) The Access app: a) sets up pass-thru query b) .SQL property of querydef is a string, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
tracyyun
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...

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.