我需要从表中获取最后一个 ID 并显示它。我试过 Scope_Identity() 但不知何故我无法得到它。消息框什么都没有显示..它是空的。这是我当前的代码:
Try
myConn.ConnectionString = "Data Source=192.168.2.222;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=sa;"
myConn.Open()
myCmd = New System.Data.SqlClient.SqlCommand("SELECT SCOPE_IDENTITY AS LastId FROM customers", myConn)
oResult = myCmd.ExecuteScalar()
If oResult IsNot Nothing Then
MsgBox(oResult.ToString)
Else
MsgBox("No Record Found")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
myConn.Close()
End Try