You are here: Re: Problem with stored procedure and retrieving inserted identity value « MsSQL Server « IT news, forums, messages
Re: Problem with stored procedure and retrieving inserted identity value

Posted by rmk on 07/11/06 15:40

select @NEWID = @@IDENTITY

should be changed to

SET @NEWID = SCOPE_IDENTITY()


"Susanne Klemm" <sklemm@gmx.de> wrote in message
news:44b39fa5$0$480$bfcc4b32@reader.news.celox.de...
> Hello!
>
> I use a procedure to insert a new row into a table with an identity
> column. The procedure has an output parameter which gives me the
> inserted identity value. This worked well for a long time. Now the
> identity value is over 700.000 and I get errors whiles retrieving the
> inserted identitiy value. If I delete rows and reset the identity
> everything works well again. So I think it is a data type problem.
>
> My Procedure:
>
> create procedure InsertProduct
> @NEWID int output
> as
> begin
> set nocount on
> insert into PRODUCT(D_CREATED)values(getdate()+'')
> set nocount off
> select @NEWID = @@IDENTITY
> end
>
> My C# code:
> SqlCommand comm = new SqlCommand("InsertProduct", sqlCon);
> comm.CommandType = CommandType.StoredProcedure;
> comm.Parameters.Add(new SqlParameter("@NEWID",
> System.Data.SqlDbType.Int)).Direction =
> System.Data.ParameterDirection.Output;
>
> try
> {
> SqlDataReader sqlRead = comm.ExecuteReader();
> object o = comm.Parameters["@NEWID"].Value;
> //...
> }
> catch ( Exception ex ){ throw ex;}
>
> The object o is alwaya System.DbNull. I also tried to use bigint.
>
> Any hints are welcome
>
> Ciao
> Susanne

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация