Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL StoredProcedures
Hi!
 
I have a problem with returning the new id of the newly inserted item in database back to C# code(i need it for displaying the new item in the form)... My stored procedure is setup, so it returns scope_identity(tried with select and output as well). But when I run
int newID = customerTableAdapter.Insert(values...)
new id is set to -1, are there some properties that need to be configured in the tableAdapter parameters collection(I tried setting the collumnName and sourceCollumn to CustomerID but nothing seems to work), so that the fuction will return the new identity, becouse the SP when run in SQL Management Studio returns the new id?
 
Thanks in advance...
 
B
Posted 1-Sep-12 23:31pm
pykos543
Edited 1-Sep-12 23:32pm
v2
Comments
Zoltán Zörgő at 2-Sep-12 5:53am
   
Post your stored procedure code here.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have a look at this blog. It has a very thorough example of returning a value from a stored procedure: http://blogs.msdn.com/b/smartclientdata/archive/2006/08/09/693113.aspx[^]
  Permalink  
Comments
pykos at 2-Sep-12 6:45am
   
Thanks this resolved my problem, and for anyone else who might have this problem, just right clic on the table adapter that you need to update and click view code, and paste the code provided in the link...and also watch out if you have another insert method(the default one for example) becouse than the parameter in adapter.GetReturnValue(2) changes also, in my case to "2"...cheers
Mika Wendelius at 2-Sep-12 6:49am
   
Glad it helped :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 359
1 Richard MacCutchan 320
2 OriginalGriff 240
3 Jared Sanow 145
4 Snehasish_Nandy 115
0 Sergey Alexandrovich Kryukov 5,969
1 OriginalGriff 5,005
2 CPallini 2,473
3 Richard MacCutchan 1,547
4 Abhinav S 1,507


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 2 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100