Getting the recordid of a record just inserted into a table in SQL server

Getting the recordid of a record just inserted into a table in SQL server

Post by Robert Hedle » Fri, 26 Jul 2002 07:57:39



Hi,

I'm using VS.NET to develop a simple application which
inserts records into a sql 2k server database.

The user inputs the data via an asp.net webform and the
code-behind page handles the execution of the sql.

To create the Insert command I drag-and-dropped a sql
table from the server explorer and updated the insert
command to reflect what i wanted.

The only thing I can't figure out what to do is retrieve
the recordid of the record just inserted.

Insert Command:

INSERT INTO newsgroup_threads
                      (newsgroupid, threadtitle)

The field I am trying to retrieve after insert
is 'threadid' which is a bigint identity field, which
auto created the 'threadid'.

The code I am using to insert the data is:

        SqlDataAdapter1.InsertCommand.Parameters

        SqlDataAdapter1.InsertCommand.Parameters

("newsgroupid")

        SqlDataAdapter1.InsertCommand.Connection.Open()
        SqlDataAdapter1.InsertCommand.ExecuteNonQuery()
        SqlDataAdapter1.InsertCommand.Connection.Close()

I would like to retrieve the 'threadid' and store it in
an integer variable for processing in later queries.

Please help.

Regards,

Robert.

 
 
 

Getting the recordid of a record just inserted into a table in SQL server

Post by Bill Cheng ( » Tue, 30 Jul 2002 22:04:15


Hi Robert,

You may check the following article:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconretrievingi...
orautonumbervalues.asp

This posting is provided "AS IS" with no warranties, and confers no rights.

Regards,

Bill Cheng
Microsoft Support Engineer
--------------------
| Content-Class: urn:content-classes:message


| Subject: Getting the recordid of a record just inserted into a table in
SQL server
| Date: Wed, 24 Jul 2002 15:57:39 -0700
| Lines: 46

| MIME-Version: 1.0
| Content-Type: text/plain;
|       charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcIzZYJXQ368Nm6vSHGM7oRxPO1IIg==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.vsnet.general
| NNTP-Posting-Host: TKMSFTNGXA07 10.201.232.166
| Path: cpmsftngxa08!cpmsftngxa07
| Xref: cpmsftngxa08 microsoft.public.vsnet.general:12927
| X-Tomcat-NG: microsoft.public.vsnet.general
|
| Hi,
|
| I'm using VS.NET to develop a simple application which
| inserts records into a sql 2k server database.
|
| The user inputs the data via an asp.net webform and the
| code-behind page handles the execution of the sql.
|
| To create the Insert command I drag-and-dropped a sql
| table from the server explorer and updated the insert
| command to reflect what i wanted.
|
| The only thing I can't figure out what to do is retrieve
| the recordid of the record just inserted.
|
| Insert Command:
|
| INSERT INTO newsgroup_threads
|                       (newsgroupid, threadtitle)

|
| The field I am trying to retrieve after insert
| is 'threadid' which is a bigint identity field, which
| auto created the 'threadid'.
|
| The code I am using to insert the data is:
|
|         SqlDataAdapter1.InsertCommand.Parameters

|         SqlDataAdapter1.InsertCommand.Parameters

| ("newsgroupid")
|
|         SqlDataAdapter1.InsertCommand.Connection.Open()
|         SqlDataAdapter1.InsertCommand.ExecuteNonQuery()
|         SqlDataAdapter1.InsertCommand.Connection.Close()
|
| I would like to retrieve the 'threadid' and store it in
| an integer variable for processing in later queries.
|
| Please help.
|
| Regards,
|
|
| Robert.
|

 
 
 

1. cannot insert more than 45 records in a table in sql ce (urgent)

Hi,

   I using compact framework (System.Data)
to insert records into sql ce.

   I can only insert 45 records in one go in a table
for my compaq iPAQ H3800 ; processor ARM SA1110
(63.14 MB). The OS is Pocket Pc
Version 3.0.11171 (build 11178).

   But if I use the emulator, I can only
insert 57 records in one go.

   I have more than 300 records to insert
in a table.

   I will appreciate if someone can reply
to me as soon as possible.

thanks
best regards
kengwee

2. how do I debug Java?

3. Copy records, change them and insert as new records into the same table?

4. Fast processing of grammers

5. How to update/delete/insert records to SQL server wit VB.NET?

6. Time Server and Software for Windows

7. Insert records in a SQL Server via DBGrid

8. FA CRASH Issue 1 to 54 and 56 to 58

9. Inserting record into a calculated field in SQL Server

10. Insert null into SQL server table

11. Getting SQL Server Table Check Constraints into Dataset

12. getting data from the sql server table in C#

13. Copy Record(s) from Access table to SQL Table