如何在DropDownList c#OleDb中组合数据库中的2列
本文关键字:组合 数据库 2列 c#OleDb DropDownList | 更新日期: 2023-09-27 18:25:51
我想从数据库中获取两列,并将其放在DropDownList中,但当我编写此代码时,软件会给我错误消息:"数据关联:System.Data.Common.DataRecordInternal不包含名为"ProductManufacturer ProductModel"的属性。"并将"ProductsList.DataBind();"放在红色中。问题是什么?我如何向ProductManufacturer&DropDownList中的ProductModel。
OleDbConnection con11 = new OleDbConnection();
con11.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("") + "''DataBases.accdb";
con11.Open();
string sql1 = "select * from ProductsTable";
OleDbCommand cmd1 = new OleDbCommand(sql1, con11);
OleDbDataReader Dr1 = cmd1.ExecuteReader();
ProductsList.DataSource =Dr1;
ProductsList.DataTextField = "ProductManufacturer" + " " + "ProductModel";
ProductsList.DataValueField = "ProductModel";
ProductsList.DataBind();
在查询中组合它们。
string sql1 = "select *, ProductManufacturer + ' ' + ProductModel as someField from ProductsTable";
ProductsList.DataTextField = "someField";