table adaptes and scope_identity()

R

Rain

Hi,

Im having a small problem. I have created an insert function which works
fine and dandy. In order to get the new row id I did the following.


Insert BLAH BLAH BLAH ;
select scope_identity();


Now I set the return type to scalar, but it insists on returning the value
1, which is the number of rows affected. Can anyone tell me what I need to
do in order to get the value without having to resort to creating another
select function to obtain it.


Thanks
 
R

Rain

Dont worry I fixed it. I had created an insert query, but left the name the
same. Insert. So the designer appears to ignore the changes you make if the
name of your query happens to be the same as the four standard ones. As soon
as I created a new one called InsertReturnId, everything worked, just one
small issue, I had to cast the return value in the sql statement first.
Cast( scope_identity() as int ).

Apart from that it works like a dream now..

Table adapters are great as long as you know the the pitfalls I think :|

Cheers
 
G

Göran Andersson

Rain said:
Hi,

Im having a small problem. I have created an insert function which works
fine and dandy. In order to get the new row id I did the following.


Insert BLAH BLAH BLAH ;
select scope_identity();


Now I set the return type to scalar, but it insists on returning the value
1, which is the number of rows affected. Can anyone tell me what I need to
do in order to get the value without having to resort to creating another
select function to obtain it.


Thanks

Your result contains to sets of data. The first set comes from the
insert query, it's empty and just contains the number of records
affected. The second set is from the select query.

To keep the insert from returning a result, do this first:

set nocount on
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,124
Latest member
JuniorPell
Top