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

  • Thread starter Thread starter Bob
  • Start date Start date
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
 
Back
Top