You are on page 1of 1

private DataTable GetData()

{
try
{
using (SqlConnection cnn = new SqlConnection(CADENA_CONEXION))
{
string sql =
"SELECT IdCliente, (CONVERT(varchar, IdCliente) + ', ' + Nombre) AS
DatosCombinados " +
"FROM Clientes";
SqlDataAdapter da = new SqlDataAdapter(sql, cnn);
DataTable dt = new DataTable("Clientes");
da.Fill(dt);
return dt;
}
}
catch (Exception ex)
{
throw;
}

}
Cuando desees cargar de datos el control ComboBox, llamaras a la funcin GetData de
la siguiente manera:
try
{
comboBox1.DataSource = GetData();
comboBox1.DisplayMember = "DatosCombinados";
comboBox1.ValueMember = "IdCliente";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

You might also like