Load id of an object in a combobox

0

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.

    
asked by dunia 19.04.2018 в 18:01
source

1 answer

0

@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 with SQL Server in this way in ComboBox the user can see the Descripción and internally you manage it with Id , Regards.

    
answered by 19.04.2018 в 21:32