Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
返回插入行VB.NET MySQL上的最后一个ID(标识)_Mysql_Vb.net_Identity - Fatal编程技术网

返回插入行VB.NET MySQL上的最后一个ID(标识)

返回插入行VB.NET MySQL上的最后一个ID(标识),mysql,vb.net,identity,Mysql,Vb.net,Identity,我想返回当前插入的自动增量值,并在msgbox中显示。您可以通过获取表的自动增量值,然后在msgbox中显示,您可以使用双查询,并在运行第一次查询后使用函数来获取最后一次当前查询: Dim insert_coupon_query As String = ("INSERT INTO qa_discountcoupons (id, status_code) VALUES (AUTO_INCREMENT_ID, 5)") Dim cmd_query As New MyS

我想返回当前插入的自动增量值,并在msgbox中显示。

您可以通过获取表的自动增量值,然后在msgbox中显示,您可以使用双查询,并在运行第一次查询后使用函数来获取最后一次当前查询:

Dim insert_coupon_query As String = ("INSERT INTO qa_discountcoupons (id, status_code) VALUES (AUTO_INCREMENT_ID, 5)")
                Dim cmd_query As New MySqlCommand(insert_coupon_query, objConn)
                Dim cmd_result As Integer = CInt(cmd_query.ExecuteScalar())

晚会有点晚,但之后

Dim insert_coupon_query As String = ("INSERT INTO qa_discountcoupons (status_code) VALUES (5); SELECT LAST_INSERT_ID()")
                Dim cmd_query As New MySqlCommand(insert_coupon_query, objConn)
                Dim cmd_result As Integer = CInt(cmd_query.ExecuteScalar())

                MsgBox(cmd_result)

生成最后一个插入id。

您是否真的按照查询建议传递了id?或者它真的是一个自动增量?在MySQL中,您可以选择
LAST\u INSERT\u ID
来获取事务中最后一个自动递增的ID。不,该ID是由MySQL生成的,我只传递状态代码。没想到我们可以在vb.net sql语句中使用双重查询。它有助于从ID列中获取自动递增编号。非常感谢。
cmd_query.ExecuteScalar()
MsgBox(cmd_query.LastInsertedId)