data binding with combobox

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!!
 
G

Ginny Caughey MVP

Diego,

Do you get any error message?

Ginny Caughey
Device Application Development MVP
 
D

Diego

Always catch an error and in his windows show the name of de
table..[Ref_Cereal]

Thanks
 
G

Ginny Caughey MVP

Deigo,

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

Ginny Caughey
Device Application Development MVP
 
G

Ginny Caughey 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
 
D

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top