In C #, I need to make a combobox that shows the description of an object but also loads the id of that object without showing the user that id.
In C #, I need to make a combobox that shows the description of an object but also loads the id of that object without showing the user that id.
@dunia look how to ask so that your subsequent questions are better received. You can also do the tour to better understand how the site works.
Here is a simple way to do what you require:
string sql = "select id, descripcion from TUTABLA";
DataSet dataset = new DataSet();
using (SqlDataAdapter da = new SqlDataAdapter(sql, conexion))
{
da.Fill(dataset);
}
if (dataset.Tables[0].Rows.Count > 0)
{
tuComboBox.DataSource = dataset.Tables[0];
tuComboBox.DisplayMember = "descripcion";
tuComboBox.ValueMember = "id";
}
conexion
is your variable or method that you use to link withSQL Server
in this way inComboBox
the user can see theDescripción
and internally you manage it withId
, Regards.