title: How can I get combobox ID to return to database
body: <pre><code>void fill_cbcategoria()
      {
          try
          {
              con.Open();
              string Query = "select * from Categoria";
              SqlCommand createCommand = new SqlCommand(Query, con);
              SqlDataReader dr = createCommand.ExecuteReader();
              while (dr.Read())
              {
                      string categoria = (string)dr.GetString(1);
                      cbcategoria.Items.Add(categoria);
              }
              con.Close();
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }
  </code></pre>
  
  <p>I am using this code to fill my category combobox:</p>
  
  <pre><code>private void btneditar_Click(object sender, EventArgs e)
      {
          try
          {
              con.Open();
              string Query = "insert into dbPAP.Categoria (id_categoria, categoria)" + "values('" + this.cbcategoria.SelectedValue + this.cbcategoria.SelectedItem + "') ;";
              SqlCommand createCommand = new SqlCommand(Query, con);
              SqlDataReader dr = createCommand.ExecuteReader();
              MessageBox.Show("Editado com sucesso!");
              while (dr.Read())
              {
  
              }
              con.Close();
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }
  </code></pre>
  
  <p>Now I want to update data to database, but is needed "<code>id_categoria</code>" but I don''t know how can I do it. In Table "<code>Categoria</code>" just got 2 parameters, that's "<code>id_categoria</code>" = 0 and "<code>categoria</code>" = 1. Problem is, can I get "<code>id_categoria</code>" value to update in database using <code>combobox.SelectedItem</code>?</p>