Link dropdown to Access database

  • Thread starter Thread starter Christian Ista
  • Start date Start date
C

Christian Ista

Hello,

In an Access database, I have 2 fields "id" and "category", the table name
is "category".

In the Page_Load, I have this :
DropDownList1.DataSource = Common.getCategory();
DropDownList1.DataBind();

In the getCategory, I have this :

public static DataSet getCategory()
{
string connection = getConnectionString();
string query="SELECT * FROM Category";

DataSet dataset = new DataSet();
OleDbConnection conn = new OleDbConnection(connection);
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(query, conn);
adapter.Fill(dataset,"category");
return dataset;
}

Compilation ok, but when I execute, I have in the dropdown 5 lines (the
number of record in the table) "System.data.DataRowView".

Could tell me how to do to have the "category" field in the dropdown.

Thanks,

Christian,
 
Could tell me how to do to have the "category" field in the dropdown.

Sorry, I forget to set DataTextField and DataValueField


Christian,
 

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