last Mysql record

Asked

Viewed 479 times

0

How to know the last ID record in the table and play the number in a textblock?

 using (_connection = new MySqlConnection("Database=test;Data Source=localhost;User Id=root;Password=teste;SslMode=None;"))
        {
            System.Text.EncodingProvider ppp;
            ppp = System.Text.CodePagesEncodingProvider.Instance;
            Encoding.RegisterProvider(ppp);

            _connection.Open();
            var cmd = new MySqlCommand("SELECT ???? FROM user", _connection);

            using (var reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    textBlock.Text = (reader.GetString("id"));
                }
            }
        }

2 answers

3


SELECT id FROM user ORDER BY id DESC LIMIT 1

2

Another option would be:

SELECT MAX(id) FROM user

Browser other questions tagged

You are not signed in. Login or sign up in order to post.