Getting the PK back from an insert sql statement, how?

B

Bob

Using sql 2005 and Vs2005 , snippet below.

Dim Conn As New SqlConnection(My.Settings.ConnectionString.ToString)

Dim cmd As New SqlCommand

Dim MYPK as long

Conn.Open()

cmd.Connection = Conn

cmd.CommandText = "Insert Into Mytable (Field1,Field2)
Values('Value1','Value2')"

"When executed, this inserts only one new row. How can I get the primary key
of that new record back into variable MYPK

Any help appreciated,

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top