Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Ms access 2013中的OleDbDataReader数据绑定DropDownList_C#_Asp.net_Ms Access_Ms Access 2013 - Fatal编程技术网

C# 使用Ms access 2013中的OleDbDataReader数据绑定DropDownList

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

我正在尝试将我的下拉列表与我的数据库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\\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如果您认为这有帮助,请向上投票并将其标记为答案