ACCESS dropdownlist 邦定数据
public partial class _Default : System.Web.UI.Page
{
private System.Data.OleDb.OleDbConnection nwindConn;
string StrCon = ConfigurationManager.ConnectionStrings["tmpdb"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
nwindConn = new OleDbConnection(StrCon);
nwindConn.Open();
string StrSql = "select * from tb ";
//SqlDataAdapter CMD = new SqlDataAdapter(StrSql, nwindConn);
OleDbDataAdapter CMD = new OleDbDataAdapter(StrSql, nwindConn);
//连接数据库
DataSet ds = new DataSet();
CMD.Fill(ds, "table1");
nwindConn.Close();
DropDownList1.DataSource = ds.Tables["table1"].DefaultView;
DropDownList1.DataValueField = "ID";
DropDownList1.DataTextField = "Name";
DropDownList1.DataBind();
}
}