Det här fungerar inte:
strSQL = "INSERT INTO tabell1 (fld1, fld2) VALUES('string1', 'string2')"
strSQL = strSQL & "; UPDATE tabell2 SET myValue = 1"
strSQL = strSQL & "; SELECT @@IDENTITY"
Set objRS = objConn.Execute(strSQL)
intId = objRS(0)
Det här fungerar:
strSQL = "INSERT INTO tabell1 (fld1, fld2) VALUES('string1', 'string2')"
strSQL = strSQL & "; UPDATE tabell2 SET myValue = 1"
objConn.Execute strSQL
strSQL = "SELECT @@IDENTITY"
Set objRS = objConn.Execute(strSQL)
intId = objRS(0)
Varför?
------------------
http://www.tavlingar.se
icaaqMedlem sedan okt. 20005 273 inlägg har du access så funkar i multipla sql kommandon .. :(
------------------
I like ¼ £ whith cheese
Jag har SQL Server
------------------
http://www.tavlingar.se
LarsGMedlem sedan dec. 200012 464 inlägg Om du har multipla satser så där så får du ett recordset för varje sqlsats. Dvs, du får två stycken tomma och ett som innehåller värdet för @@identity
strSQL = "set nocount on;INSERT INTO tabell1 (fld1, fld2) VALUES('string1', 'string2')"
strSQL = strSQL & "; UPDATE tabell2 SET myValue = 1"
strSQL = strSQL & "; set nocount off; SELECT @@IDENTITY"
Set objRS = objConn.Execute(strSQL)
intId = objRS(0)
Om man lägger till set nocount on så skapas det inga recordset.
------------------
essentitia preter non sans multiplicandum
Tackar. Fungerar.
------------------
http://www.tavlingar.se