Llenar combobox + Compact framework

17/06/2008 - 15:57 por Diego | Informe spam
Quiero llenar un combobox y no encuentro la manera, este es mi codigo con el
que no logro bindear los datos al combo.


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlServerCe;

using System.IO;



namespace Consulta_Rodeos

{

public partial class cereal : Form

{

// Fields


private DataSet ds;

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 comando

SqlCeCommand cmd = conn.CreateCommand();

cmd.CommandText = " select * from Ref_Cereal'";

//Abrimos la conexion

if (conn.State == System.Data.ConnectionState.Closed)

conn.Open();

//Defino adaptador


//Adaptador = SqlceDataAdapter("SELECT * FROM REF_CEREAL ORDER BY DESCRIP",
conn);

// Create the DataSet

ds = new DataSet("Ref_Cereal");

// Fill the Dataset with Customers, map Default Tablename

// "Table" to "ref_cereal".

SqlCeDataAdapter da1 = new SqlCeDataAdapter("SELECT * FROM Ref_Cereal order
by descrip", conn);

da1.Fill (ds, "Ref_Cereal");



// Combobox Databinding


this.comboBox1.DataSource = ds.tables("ref_cereal");

this.comboBox1.DisplayMember = "descrip";// ' El nombre que mostras

this.comboBox1.ValueMember = "codigo"; //'El dato que queres retornar








}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

{

}

}

}

Gracias.
Diego
 

Leer las respuestas

#1 Fernando Gómez
17/06/2008 - 17:25 | Informe spam
Diego wrote:
Quiero llenar un combobox y no encuentro la manera, este es mi codigo con el
que no logro bindear los datos al combo.


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlServerCe;

using System.IO;



namespace Consulta_Rodeos

{

public partial class cereal : Form

{

// Fields


private DataSet ds;

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 comando

SqlCeCommand cmd = conn.CreateCommand();

cmd.CommandText = " select * from Ref_Cereal'";

//Abrimos la conexion

if (conn.State == System.Data.ConnectionState.Closed)

conn.Open();

//Defino adaptador


//Adaptador = SqlceDataAdapter("SELECT * FROM REF_CEREAL ORDER BY DESCRIP",
conn);

// Create the DataSet

ds = new DataSet("Ref_Cereal");

// Fill the Dataset with Customers, map Default Tablename

// "Table" to "ref_cereal".

SqlCeDataAdapter da1 = new SqlCeDataAdapter("SELECT * FROM Ref_Cereal order
by descrip", conn);

da1.Fill (ds, "Ref_Cereal");



// Combobox Databinding


this.comboBox1.DataSource = ds.tables("ref_cereal");

this.comboBox1.DisplayMember = "descrip";// ' El nombre que mostras

this.comboBox1.ValueMember = "codigo"; //'El dato que queres retornar








}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

{

}

}

}

Gracias.



http://www.google.com.mx/search?q=i...rg.mozilla:en-US:official&client=firefox-a

La primera opción parece ser la correcta.

Preguntas similares