I am an ASP .NET beginner, so please bear with me.
I have a database named Product which contains columns ProductName and ProductID.
I want to display all ProductName values in dropdownlist. For this, I first put all the values in a dataset and from there, I bind them to dropdownlist. But in the output, instead of ProductName values, I am getting the following values in dropdownlist:
System.Data.DataRowView
(Repeated equal to the number of rows in database)
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
public partial class Demo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\Database2.mdb;Persist Security Info=True");
DataSet ds = new DataSet();
string query = "SELECT ProductName FROM Product";
OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn);
conn.Open();
adapter.Fill(ds, "Table1");
conn.Close();
DropDownList1.DataSource = ds;
DropDownList1.DataBind();
}
}
}
Any idea what I am missing here? Your help will will be appreciated. Thanks.