本文介绍了从MySQL返回最后插入的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一点麻烦用下面的查询:
I'm having a bit of trouble with the following query:
START TRANSACTION; SET @LASTID = 0; INSERT INTO `Accounts` (`Col1`,`col2`,`col3`,`col4`) VALUES (@param1,@param2,@param3,@param4); SET @LASTID = last_insert_id(); -- This is what I need INSERT INTO `Users` (`usr1`,`usr2`,`usr3`,`usr4`) VALUES (@usr1,@usr2,@usr3,@usr4); SELECT @LASTID; COMMIT;基本上,我需要从账目表中返回最后插入的ID,但是运行SELECT @LASTID时,则MySQL返回一个blob,而不是一个单一的值,这我无法在C#asp访问
Basically, I need to return the last inserted ID from the accounts table, however when running SELECT @LASTID, MySql returns a blob rather than a single value, which I'm having trouble accessing in C# asp
有没有简单的方法来获得这个值作为一个int / VARCHAR?从斑点在code我觉得转换是矫枉过正了,我想,解除离开到MySQL服务器。
Is there any simple way to get this value as an int / varchar? Converting from blobs in code i feel is overkill, and I'd like to leave that lifting to the Mysql server.
先谢谢了。
推荐答案使用
SELECT LAST_INSERT_ID();的dev.mysql/doc/refman/5.0/en/information-functions.html#function_last-insert-id
更多推荐
从MySQL返回最后插入的ID
发布评论