473,395 Members | 1,530 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,395 software developers and data experts.

SQL Server @@identity Problem

The below code does _not_ work! The datatype for the autoincrement value is
INT in SQL Server 2000. The strange thing is that if I use a 'decimal' it
works (using .NET framework 1.1)

---------------------------------------------------------
string sql = "insert into sports (name) value ('test'); select @@identity";

conn.Open();

SqlCommand cmd = new SqlCommand(sql, conn);
int result = (int)cmd.ExecuteScalar();
----------------------------------------------------------

Thanks in advance
Nov 15 '05 #1
1 3622
This is an expected type conversion error. For details, see:

@@IDENTITY:
http://msdn.microsoft.com/library/en...obals_50u1.asp
numeric data type:
http://msdn.microsoft.com/library/en...de-dz_3grn.asp
SQL type mapping:
http://msdn.microsoft.com/library/en...taSqlTypes.asp
SqlDecimal type conversions:
http://msdn.microsoft.com/library/en...atorsTopic.asp
"Micheal" <fr****@sbcglobal.net> wrote in message
news:OB*************@TK2MSFTNGP10.phx.gbl...
The below code does _not_ work! The datatype for the autoincrement value is INT in SQL Server 2000. The strange thing is that if I use a 'decimal' it
works (using .NET framework 1.1)

---------------------------------------------------------
string sql = "insert into sports (name) value ('test'); select @@identity";
conn.Open();

SqlCommand cmd = new SqlCommand(sql, conn);
int result = (int)cmd.ExecuteScalar();
----------------------------------------------------------

Thanks in advance

Nov 15 '05 #2

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

Similar topics

5
by: DBA | last post by:
I have an identity field on a table in SQL Server. The identity seed is 1 and the identity increment is 1. If I remove a record from this table, the identity sequence is broken. For example: ...
5
by: grzes | last post by:
MS SQL Server 2000. My case is: I have the table T with primary key calling __recid int without identity property. This table includes a lot of records (about 1000000). I need to convert __recid's...
17
by: Trevor Best | last post by:
I don't know if this has been reported before but it appears to be a bug with Access. If I create two tables both with an identity column then create an insert trigger on table1 that inserts a...
4
by: Brian Henry | last post by:
I an trying to connect to a sql server in asp.net with the sql connection object, and every time i try to open the connection i get this Server Error in '/' Application. Login failed for user...
5
by: Darin Shaw | last post by:
I'm receiving a "specified cast is invalid" with the following code, though I've used the exact same code in other applications with success. Can anyone tell me what I'm missing or if there are...
4
by: Sandeep | last post by:
All, First let me explain My Application's deployment scenerio. My Application server is on win2003 + IIS6.0. I created a local user called XYZ on the server. My web application's pool run under...
2
by: pvl | last post by:
Hi We have the following scenario: 1. SQL server 2000 on Windows 2003 Server 2. Web server 1, running web service 1 on Windows 2003 Server 3. Web server 2, running web service 2 on Windows 2000...
2
abdoelmasry
by: abdoelmasry | last post by:
Hi men i have big problem with microsoft exchange server 2003 i installed exchange server as main mail server to use it on in company i have static real ip address im sending and...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.