469,926 Members | 1,514 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

Q: fetch identity field

Hello,

Let say myTable has two fields: ID and Name. ID is an identity field and
increased sequentially by 1 each time a record is entered into table.
dr["Name"]=”MayName”;
dataSet11.Tables[myTable].Rows.Add(dr);
sqlDataAdapter1.Update(dataSet11, myTable);

Now after update, I need to find what the ID value is for the record I just
added. This is a multi-user environment. How should I fetch it?

Thanks,

Nov 19 '05 #1
3 1115
Make a batch and use SCOPE_IDENTITY(). Look up Transact SQL help for
details.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
Hello,

Let say myTable has two fields: ID and Name. ID is an identity field and
increased sequentially by 1 each time a record is entered into table.
dr["Name"]="MayName";
dataSet11.Tables[myTable].Rows.Add(dr);
sqlDataAdapter1.Update(dataSet11, myTable);

Now after update, I need to find what the ID value is for the record I just added. This is a multi-user environment. How should I fetch it?

Thanks,


Nov 19 '05 #2
Eliyahu,
Thanks for your help.
I found this:

Dim myconn As New SqlConnection("yourconnectionstring")
strsql = "INSERT INTO TABLENAME (COLUMN) VALUES ('" &somevalue &"'); SELECT
SCOPE_IDENTITY() AS LAST_INSERT "
myconn.Open()
Dim mycommand As New SqlCommand(strsql, myconn)
Dim lastinsert As Integer = CType(mycommand.ExecuteScalar(), Integer)
myconn.Close()

Any idea how I can convert this so that it will work with my
sqlDataAdapter1.Update(dataSet11, myTable); command?
"Eliyahu Goldin" wrote:
Make a batch and use SCOPE_IDENTITY(). Look up Transact SQL help for
details.

Eliyahu

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
Hello,

Let say myTable has two fields: ID and Name. ID is an identity field and
increased sequentially by 1 each time a record is entered into table.
dr["Name"]="MayName";
dataSet11.Tables[myTable].Rows.Add(dr);
sqlDataAdapter1.Update(dataSet11, myTable);

Now after update, I need to find what the ID value is for the record I

just
added. This is a multi-user environment. How should I fetch it?

Thanks,


Nov 19 '05 #3
On Wed, 13 Jul 2005 04:49:04 -0700, JIM.H. <JI**@discussions.microsoft.com> wrote:

Hello,

Let say myTable has two fields: ID and Name. ID is an identity field and
increased sequentially by 1 each time a record is entered into table.


dr["Name"]=MayName;
dataSet11.Tables[myTable].Rows.Add(dr);
sqlDataAdapter1.Update(dataSet11, myTable);

Now after update, I need to find what the ID value is for the record I just
added. This is a multi-user environment. How should I fetch it?

See the following:

HOW TO: Retrieve an Identity Value from a Newly Inserted Record from SQL Server by Using Visual
Basic .NET
http://support.microsoft.com/default...b;en-us;320141
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ann | last post: by
2 posts views Thread by Andrew Grandison | last post: by
5 posts views Thread by DBA | last post: by
4 posts views Thread by newtophp2000 | last post: by
9 posts views Thread by =?Utf-8?B?UHJhdmlu?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.