data binding with combobox

  • Thread starter Thread starter Diego
  • Start date Start date
D

Diego

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,

Do you get any error message?

Ginny Caughey
Device Application Development MVP
 
Deigo,

Is there an InnerException? Are you sure the table exists?

Ginny Caughey
Device Application Development MVP
 
Diego,

It certainly doesn't seem to like that table name. I can't tell what your constructor for the adapter looks like. Perhaps the problem is there?

Ginny
The table in the database exist.

If omit try and catch, VS showed the error in the line:

adapter.Fill(ds, "Ref_cereal"); señalando a "Ref_Cereal" aqnd saying that SqlCeException is not controled, attach image of screen

and in Results:
Excepción del tipo 'System.Data.SqlServerCe.SqlCeException' en System.Data.SqlServerCe.dll



Thanks.



Diego
 
It certainly doesn't seem to like that table name

change the name?

I can't tell what your constructor for the adapter looks like.

For why?

That you suggest?

Thanks a lot.

Diego
 
Back
Top