title: Datagridview select last insert row what i insert via database
body: <p>I want to select row what is last insert in database. When i insert data in database datagridview is refreshed and he retrive last row what i insert. My problem is that i no have idea how to select last insert row. I have last insert id and how now to 
  <a href="https://i.stack.imgur.com/cvHdd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cvHdd.png" alt="enter image description here"></a></p>
  
  <p>When i click on save button new item is added to database, grid is refreshed and he show new row.How to automaticly after success save data select row like <strong>id 30 in grid</strong></p>
  
  <pre><code>private void sacuvajPromeneButton_Click(object sender, EventArgs e)
  {
      using (var pleaseWaitForm = new Loading())
      {
          pleaseWaitForm.Show();
  
          Application.DoEvents();
  
          using (var conn = new MySqlConnection(Database.connStringStatic))
          {
              try
              {
                  conn.Open();
  
                  using (MySqlCommand cmd = conn.CreateCommand())
                  {
  
                      cmd.Parameters.AddWithValue("@ime", primalac_ime_textBox.Text);
                      cmd.Parameters.AddWithValue("@prezime", primalac_prezime_textBox.Text);
                      cmd.Parameters.AddWithValue("@grupa_id", 1);
                      cmd.Parameters.AddWithValue("@ulica", primalac_ulica_textBox.Text);
                      cmd.Parameters.AddWithValue("@grad", primalac_grad_textBox.Text);
                      cmd.Parameters.AddWithValue("@postanski_br", primalac_postanskiBroj_textBox.Text);
                      cmd.Parameters.AddWithValue("@jmbg", posiljalac_jmb_textBox2.Text);
                      cmd.Parameters.AddWithValue("@telefon", primalac_kontakt_textBox.Text);
                      cmd.Parameters.AddWithValue("@telefon_2", telefon2_textBox1.Text);
                      cmd.Parameters.AddWithValue("@email", posiljalac_email_textBox3.Text);
                      cmd.Parameters.AddWithValue("@napomena", napomenarichTextBox1.Text);
                      cmd.Parameters.AddWithValue("@datum_kreiranja", DateTime.Now);
  
                     // cmd.CommandType = CommandType.StoredProcedure;
                      cmd.CommandText = "CALL kreiraj_korisnika(@ime, @prezime, @grupa_id, @ulica, @grad, @postanski_br, @jmbg, @telefon, @telefon_2, @email, @napomena, @datum_kreiranja)";
                      cmd.ExecuteNonQuery();
  
                      long lastInsertId= cmd.LastInsertedId;
  
                      // Refresh grid
                      dataGridView1.DataSource = null;
                      bs.DataSource = GetDat("SELECT id, ime, prezime, ulica, grad, postanski_br, telefon FROM korisnici ORDER by id");
                      dataGridView1.DataSource = bs;
  
  
                     // Test selecting
  
  
                      pleaseWaitForm.Close();
  
                      MessageBox.Show("User created.");
  
                      // Now select that new created user in grid
                     // dataGridView1.Rows[4].Selected = true;
  
  
                      this.Activate();
  
                      sacuvajPromeneButton.Visible = false;
  
  
                  }
              }
              catch(MySqlException ex)
              {
                  MessageBox.Show(ex.Message);
              }
  
          }
  
      }
  }
  </code></pre>