[英]Get id of last updated row mysql in vb.net
I tried using SELECT LAST_INSERT_ID() to get last id updated but it gives me zero. 我尝试使用SELECT LAST_INSERT_ID()来获取最新的ID,但它给了我零。 please help me 请帮我
If you're using Connector/.NET, you will find that the MySqlCommand object has a LastInsertedId property. 如果您使用的是Connector / .NET,则会发现MySqlCommand对象具有LastInsertedId属性。 You can use retrieve that property value immediately after your INSERT
query, and you don't have to execute another query. 您可以在INSERT
查询之后立即使用检索该属性值,而不必执行其他查询。
If you're not doing INSERT
operations, you won't get any LAST_INSERTED_ID()
value. 如果您不执行INSERT
操作,则不会获得任何LAST_INSERTED_ID()
值。 If all you're doing is UPDATE
querys, forget about LAST_INSERTED_ID()
. 如果您要做的只是UPDATE
查询,则无需考虑LAST_INSERTED_ID()
。
add your table a new column with DATETIME
type. 将表添加一个具有DATETIME
类型的新列。 and choose on update CURRENT timestamp
option from attribute
section. 并从attribute
部分中选择on update CURRENT timestamp
选项。 In this way whenever an update occurs in the column your database will update this row automaticly. 这样,只要该列中发生更新,您的数据库就会自动更新该行。 Then all yo need to do is writing your SQL command from your script. 然后,您所需要做的就是从脚本中编写SQL命令。
SELECT id fROM table ORDER BY name_of_datetime_column DESC LIMIT 1
will return only one column which is last updated one 将仅返回最后更新的一列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.