This simple sample example shows you how to show a column dable in a ListBox control. I 've used norhtwind.mdb Access 2000 database comes with Office 2000.
ListBox is generally used to display one or multiple columns. In this sample example, I'd show the contents of "FirstName" column of "Employees" table.
Some well known steps:
OleDbDataAdapter da = new OleDbDataAdapter( "Select * from Employees", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files\\Microsoft Office\\Office\\Samples\\Northwind.mdb");
// Create a DataSet ObjectDataSet ds = new DataSet();// Fill DataSet with the datada.Fill(ds, "Employees");
// Set DataSource property of ListBox as DataSet's DefaultViewListBox1.DataSource = ds.Tables["Employees"].DefaultView;ListBox1.SelectedIndex = 0;// Set Field Name you want to get data fromListBox1.DataTextField = "FirstName";// Bind the dataPage.DataBind();
Sample Code:
private void Page_Load(object sender, System.EventArgs e){// Put user code to initialize the page here// Create an object of OleDbDataAdapterOleDbDataAdapter da = new OleDbDataAdapter( "Select * from Employees", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files\\Microsoft Office\\Office\\Samples\\Northwind.mdb");// Create a DataSet ObjectDataSet ds = new DataSet();// Fill DataSet with the datada.Fill(ds, "Employees");// Set DataSource property of ListBox as DataSet's DefaultViewListBox1.DataSource = ds.Tables["Employees"].DefaultView; ListBox1.SelectedIndex = 0;// Set Field Name you want to get data fromListBox1.DataTextField = "FirstName";// Bind the dataPage.DataBind();}