data binding with combobox



that wrong with this code?

namespace Consulta_Rodeos

{

public partial class cereal : Form

{


public cereal()

{

InitializeComponent();

}

private void cereal_Load(object sender, EventArgs e)

{


//Creamos la cadena de conexion

string pathDir =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

string pathDB = System.IO.Path.Combine(pathDir, "ctagrom.sdf");

string connectionString = string.Empty;

connectionString = string.Format(@"DataSource={0}", pathDB);

//Creamos el objeto conexion

SqlCeConnection conn = new SqlCeConnection(connectionString);

//Creamos el objeto DataAdatper

SqlCeDataAdapter adapter = new SqlCeDataAdapter("SELECT * FROM Ref_Cereal
ORDER BY DESCRIP", conn);

//Creamos el objeto DataSet

DataSet ds = new DataSet("ds");

//Poblamos el objeto DataSet usando el adaptador

try

{

adapter.Fill(ds, "Ref_Cereal");

//Enlazamos los datos del dataSet a un objeto

listBox1.DataSource = ds.Tables["Ref_Cereal"];

listBox1.DisplayMember = "descrip";

listBox1.ValueMember = "cod_cereal";


adapter = null;

}

catch (SqlCeException __ERR)

{

MessageBox.Show(__ERR.Message.ToString());

}

}

Thanks!!

--
Diego


.



Relevant Pages


Loading