C# 使用Ms access 2013中的OleDbDataReader数据绑定DropDownList
我正在尝试将我的下拉列表与我的数据库MS Access 2013(accdb文件)进行数据绑定。这是我的代码C# 使用Ms access 2013中的OleDbDataReader数据绑定DropDownList,c#,asp.net,ms-access,ms-access-2013,C#,Asp.net,Ms Access,Ms Access 2013,我正在尝试将我的下拉列表与我的数据库MS Access 2013(accdb文件)进行数据绑定。这是我的代码 protected void Page_Load(object sender, EventArgs e) { string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networkl
protected void Page_Load(object sender, EventArgs e)
{
string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networklab1\\bin\\weblabdb.accdb";
OleDbConnection db = new OleDbConnection(str);
db.Open();
string st = "select areaName from area;";
OleDbCommand dbc = new OleDbCommand(st, db);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataBind();
read.Close();
db.Close();
}
我得到的是一行“System.Data.Common.DataRecordInternal”
我的错误是什么,如何解决!!!
谢谢您没有检查
回发
以及您的数据文本字段
和数据值字段
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networklab1\\bin\\weblabdb.accdb";
OleDbConnection db = new OleDbConnection(str);
db.Open();
string st = "select areaName from area;";
OleDbCommand dbc = new OleDbCommand(st, db);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataTextField="areaName"; //missing this
DropDownList1.DataValueField="areaName"; //missing this
DropDownList1.DataBind();
read.Close();
db.Close();
}
}
您缺少检查
Postback
以及缺少DataTextField
和DataValueField
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networklab1\\bin\\weblabdb.accdb";
OleDbConnection db = new OleDbConnection(str);
db.Open();
string st = "select areaName from area;";
OleDbCommand dbc = new OleDbCommand(st, db);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataTextField="areaName"; //missing this
DropDownList1.DataValueField="areaName"; //missing this
DropDownList1.DataBind();
read.Close();
db.Close();
}
}
您缺少检查
Postback
以及缺少DataTextField
和DataValueField
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networklab1\\bin\\weblabdb.accdb";
OleDbConnection db = new OleDbConnection(str);
db.Open();
string st = "select areaName from area;";
OleDbCommand dbc = new OleDbCommand(st, db);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataTextField="areaName"; //missing this
DropDownList1.DataValueField="areaName"; //missing this
DropDownList1.DataBind();
read.Close();
db.Close();
}
}
您缺少检查
Postback
以及缺少DataTextField
和DataValueField
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networklab1\\bin\\weblabdb.accdb";
OleDbConnection db = new OleDbConnection(str);
db.Open();
string st = "select areaName from area;";
OleDbCommand dbc = new OleDbCommand(st, db);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataTextField="areaName"; //missing this
DropDownList1.DataValueField="areaName"; //missing this
DropDownList1.DataBind();
read.Close();
db.Close();
}
}
缺少DataTextField和DataValueField。请尝试此操作-
protected void Page_Load(object sender, EventArgs e)
{
string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networklab1\\bin\\weblabdb.accdb";
OleDbConnection db = new OleDbConnection(str);
db.Open();
string st = "select areaName from area;";
OleDbCommand dbc = new OleDbCommand(st, db);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataTextField="ShownTextFieldFromDatabaseResults";;
DropDownList1.DataValueField="ValueFieldFromDatabaseResults";
DropDownList1.DataBind();
read.Close();
db.Close();
}
缺少DataTextField和DataValueField。请尝试此操作-
protected void Page_Load(object sender, EventArgs e)
{
string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networklab1\\bin\\weblabdb.accdb";
OleDbConnection db = new OleDbConnection(str);
db.Open();
string st = "select areaName from area;";
OleDbCommand dbc = new OleDbCommand(st, db);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataTextField="ShownTextFieldFromDatabaseResults";;
DropDownList1.DataValueField="ValueFieldFromDatabaseResults";
DropDownList1.DataBind();
read.Close();
db.Close();
}
缺少DataTextField和DataValueField。请尝试此操作-
protected void Page_Load(object sender, EventArgs e)
{
string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networklab1\\bin\\weblabdb.accdb";
OleDbConnection db = new OleDbConnection(str);
db.Open();
string st = "select areaName from area;";
OleDbCommand dbc = new OleDbCommand(st, db);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataTextField="ShownTextFieldFromDatabaseResults";;
DropDownList1.DataValueField="ValueFieldFromDatabaseResults";
DropDownList1.DataBind();
read.Close();
db.Close();
}
缺少DataTextField和DataValueField。请尝试此操作-
protected void Page_Load(object sender, EventArgs e)
{
string str = "Provider=Microsoft.ACE.OleDB.12.0; Data Source=C:\\Users\\Dima\\Documents\\Visual Studio 2013\\Projects\\networklab1\\bin\\weblabdb.accdb";
OleDbConnection db = new OleDbConnection(str);
db.Open();
string st = "select areaName from area;";
OleDbCommand dbc = new OleDbCommand(st, db);
OleDbDataReader read = dbc.ExecuteReader();
DropDownList1.DataSource = read;
DropDownList1.DataTextField="ShownTextFieldFromDatabaseResults";;
DropDownList1.DataValueField="ValueFieldFromDatabaseResults";
DropDownList1.DataBind();
read.Close();
db.Close();
}
@Pantelevdima向上投票,并将其标记为答案,如果您认为这是正确的helpful@PanteleevDima如果您认为这是正确的,请向上投票并将其标记为答案helpful@PanteleevDima如果您认为这是正确的,请向上投票并将其标记为答案helpful@PanteleevDima如果您认为这有帮助,请向上投票并将其标记为答案