【发布时间】:2015-02-02 03:02:55
【问题描述】:
我是 ASP .NET 初学者,请多多包涵。
我有一个名为Product 的数据库,其中包含ProductName 和ProductID 列。
我想在下拉列表中显示所有ProductName 值。为此,我首先将所有值放入数据集中,然后从那里将它们绑定到下拉列表。但在输出中,我在下拉列表中得到以下值,而不是 ProductName 值:
System.Data.DataRowView
(重复等于数据库中的行数)
这是我的代码:
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();
}
}
}
知道我在这里缺少什么吗?您的帮助将不胜感激。谢谢。
【问题讨论】: