last mysql record

0

How to know the last record of the ID 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"));
                }
            }
        }
    
asked by anonymous 10.03.2017 / 10:39

2 answers

3
SELECT id FROM user ORDER BY id DESC LIMIT 1
    
10.03.2017 / 10:52
2

Another option would be:

SELECT MAX(id) FROM user
    
10.03.2017 / 14:04