I have a product registration screen with a LOCAL Combobox. Product table has LOCAL ID, called pro_local. And the local table the fields loc_cod and loc_descricao
My combobox is populated with the function:
public DataTable RetornaLocal()
{
SqlConnection sqlConnection = acessoDadosSqlServer.CriarConexao();
sqlConnection.Open();
SqlCommand sqlCommand = sqlConnection.CreateCommand();
sqlCommand.CommandText = "SELECT * FROM local ORDER BY loc_descricao";
SqlDataReader sqlDataReader = null;
sqlDataReader = sqlCommand.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(sqlDataReader);
return dataTable;
}
In Product Form:
cbLocal.DisplayMember = "loc_descricao";
cbLocal.ValueMember = "loc_cod";
cbLocal.DataSource = localNegocios.RetornaLocal();
These functions populate the combobox, but when I bring the product form to change this product, it brings the combobox as if it were an insert, it does not have the selected pro_local saved in the database. How do I populate a combobox with a given ID at the top?
Att.