嗨,我在下面有一些代码,我希望在执行 SQL 语句时返回结果标识号。
set objCnn = Server.CreateObject("ADODB.connection")
CurrMachine = "my-test-box"
ObjCnn.Open("Provider=SQLOLEDB;Persist Security Info=False;User ID=Test;password=Test123;Language=British;Initial Catalog=TestDB;Data Source=" & CurrMachine)
strSQL = "INSERT INTO dbo.xyz" & _ " (field) " & _ " VALUES (" & date & ")" & _ " SELECT @@Identity "
objCnn.Execute strSQL
我添加了 SELECT @@Identity,当我在 SQL 中执行此操作时,它将返回唯一的 ID 号。如果我 response.write strSQL 我得到 SQL 字符串而不是结果文本。
干杯!
编辑
为你理查德
set objCnn = Server.CreateObject("ADODB.connection")
CurrMachine = "my-test-srv"
ObjCnn.Open("Provider=SQLOLEDB;Persist Security Info=False;User ID=Test;password=Test123;Language=British;Initial Catalog=Test;Data Source=" & CurrMachine)
strSQL = "INSERT INTO xyz" & _
" ([date])" & _
" VALUES ( " & date & " )" & _
" SET NOCOUNT OFF; SELECT SCOPE_IDENTITY() ID; "
Set rs = objCnn.Execute(strSQL)
response.write rs("ID")