ComboBox, OleDb's, DataBinding

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got the following code in my form's Load event handler:

OleDbConnection oleDbConnection = new OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", databaseFilename));
string sqlstr = @"SELECT * FROM Companies";
companyOleDbDataAdapter = new OleDbDataAdapter(sqlstr, oleDbConnection);
companyOleDbDataAdapter.Fill(companyDataSet, "Companies");
DataView dataView = companyDataSet.Tables["Companies"].DefaultView;
companyComboBox.DisplayMember = "CompanyName";
companyComboBox.DataSource = dataView;

After Fill is executed, the dataset contains the 1 table with 1 row. Setting DisplayMember and DataSource both succeed without errors. This is the end of the method. When the control is displayed, nothing is in the combobox. Am I missing a databinding step?

T. Ford
 
It works fine for me (had to use another database though)
Are you sure that the column is called "CompanyName"
(and not "companyname", "Companyname" or similar)?

/claes

T. Ford said:
I've got the following code in my form's Load event handler:

OleDbConnection oleDbConnection = new
OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source={0}", databaseFilename));
string sqlstr = @"SELECT * FROM Companies";
companyOleDbDataAdapter = new OleDbDataAdapter(sqlstr, oleDbConnection);
companyOleDbDataAdapter.Fill(companyDataSet, "Companies");
DataView dataView = companyDataSet.Tables["Companies"].DefaultView;
companyComboBox.DisplayMember = "CompanyName";
companyComboBox.DataSource = dataView;

After Fill is executed, the dataset contains the 1 table with 1 row.
Setting DisplayMember and DataSource both succeed without errors. This is
the end of the method. When the control is displayed, nothing is in the
combobox. Am I missing a databinding step?
 
Yep, checked the column name and table name, everything is correct. Any other ideas?

Claes Bergefall said:
It works fine for me (had to use another database though)
Are you sure that the column is called "CompanyName"
(and not "companyname", "Companyname" or similar)?

/claes

T. Ford said:
I've got the following code in my form's Load event handler:

OleDbConnection oleDbConnection = new
OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source={0}", databaseFilename));
string sqlstr = @"SELECT * FROM Companies";
companyOleDbDataAdapter = new OleDbDataAdapter(sqlstr, oleDbConnection);
companyOleDbDataAdapter.Fill(companyDataSet, "Companies");
DataView dataView = companyDataSet.Tables["Companies"].DefaultView;
companyComboBox.DisplayMember = "CompanyName";
companyComboBox.DataSource = dataView;

After Fill is executed, the dataset contains the 1 table with 1 row.
Setting DisplayMember and DataSource both succeed without errors. This is
the end of the method. When the control is displayed, nothing is in the
combobox. Am I missing a databinding step?
 
No, sorry. If the names of the table and column are correctly spelled
(including the case)
it should work. Perhaps you could try it with another database (I used the
Northwind database).

/claes



T. Ford said:
Yep, checked the column name and table name, everything is correct. Any other ideas?

Claes Bergefall said:
It works fine for me (had to use another database though)
Are you sure that the column is called "CompanyName"
(and not "companyname", "Companyname" or similar)?

/claes

T. Ford said:
I've got the following code in my form's Load event handler:

OleDbConnection oleDbConnection = new
OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source={0}", databaseFilename));
string sqlstr = @"SELECT * FROM Companies";
companyOleDbDataAdapter = new OleDbDataAdapter(sqlstr, oleDbConnection);
companyOleDbDataAdapter.Fill(companyDataSet, "Companies");
DataView dataView = companyDataSet.Tables["Companies"].DefaultView;
companyComboBox.DisplayMember = "CompanyName";
companyComboBox.DataSource = dataView;

After Fill is executed, the dataset contains the 1 table with 1 row.
Setting DisplayMember and DataSource both succeed without errors. This is
the end of the method. When the control is displayed, nothing is in the
combobox. Am I missing a databinding step?
 

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

Back
Top