I am new in vb.net and MySQL database, i am to far from what i am practicing but suddenly i'm stack in getting the value of the current data of the attribute from my table which is auto increment after inserting my query. Here is my code:
Imports MySql.Data.MySqlClient
Try
Dim dbcon As New MySqlConnection
Public dbcom As New MySqlCommand
Public sql As String
Dim theID As String ' this is the variable where the auto increment ID will be stored.
dbcon.ConnectionString = "server=localhost; uid=root; pwd=; database=test;"
dbcon.Open()
sql = "insert into tableThis values('" & Name & "');" 'this will produced an auto increment value
dbcom = New MySqlCommand(sql, dbcon)
dbcom.ExecuteNonQuery()
MsgBox("Added!Your ID IS: ", & theID) ' the auto increment ID will be display
Catch ex As Exception
MsgBox("Error!")
Exit Sub
End Try
** my table is:
-------------------------------------
-- tableThis ----
-------------------------------------
-- id -- INTEGER (AUTO_INCREMENT) -
-- name -- CHAR -
-------------------------------------
Thanks! Sorry for my bad English.