1
我需要從表中獲取最後一個ID並顯示它。我試過Scope_Identity(),但不知何故我無法得到它。消息框什麼也沒有顯示。它是空的。這裏是我當前的代碼:vb.net得到最後一個ID並顯示它
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
似乎SCOPE_IDENTITY插入SQL語句之後的作品。 –