1:UsingconnAs NewMySqlConnection("server=localhost;user id=root;password=12345;database=test") 2:UsingcmdAs NewMySqlCommand("SHOW TABLE STATUS LIKE 'tabela'", conn) 3:Try4: conn.Open() 5:CatchexAs Exception6: MsgBox("Houve um erro ao abrir uma conexão com o servidor" & vbNewLine & vbNewLine & ex.ToString) 7:End Try8:Try9:UsingrdrAsMySqlDataReader = cmd.ExecuteReader() 10:Whilerdr.Read() 11: Label1.Text = rdr.Item("Auto_increment")' Aqui recebemos o proximo auto-increment12: 13:End While14:End Using15:CatchexAs Exception16: MsgBox("Erro" & vbNewLine & vbNewLine & ex.ToString) 17:End Try18:End Using19:End Using
Você também pode usar em uma função que retorne um valor;
1:Public FunctionProximoIncrement ()As Integer2:UsingconnAs NewMySqlConnection("server=localhost;user id=root;password=12345;database=test") 3:UsingcmdAs NewMySqlCommand("SHOW TABLE STATUS LIKE 'tabela'", conn) 4:Try5: conn.Open() 6:CatchexAs Exception7: MsgBox("Houve um erro ao abrir uma conexão com o servidor" & vbNewLine & vbNewLine & ex.ToString) 8:End Try9:Try10:UsingrdrAsMySqlDataReader = cmd.ExecuteReader() 11:Whilerdr.Read() 12: Return(Convert.ToInt32(rdr.Item("Auto_increment"))) 13:End While14:End Using15:CatchexAs Exception16: MsgBox("Erro" & vbNewLine & vbNewLine & ex.ToString) 17:End Try18:End Using19:End Using
Para chama-la;
1:Try2: Label1.Text = ProximoIncrement() 3:CatchexAs Exception4: MsgBox("Houve um erro ao tentar buscar o proximo increment" & VbNewLine & ex.ToString) 5:End Try
0 comentários:
Postar um comentário