C#做WEB窗体项目,DropDownList怎么连接ACCESS数据库?

来源:百度知道 编辑:UC知道 时间:2024/09/24 10:23:50
本来DropDownList设置一下 选择数据源就行了 但不允许用这个方法 ;请问用代码怎么写DropDownList连接ACCESS数据库?谢谢!
一楼
看不懂!
你可以帮我改成DropDownList连接ACCESS数据库的吗?
谢谢!

SqlConnection conn =new SqlConnection("Data Source=.;Initial Catalog=ShopingNet;Integrated Security=True");
conn.Open();
SqlDataAdapter da=new SqlDataAdapter ("select * from Tab_ProductClass",conn);
DataSet ds=new DataSet();
da.Fill(ds, "Tab_ProductClass");
DropDownList1.DataSource = ds.Tables["Tab_ProductClass"].DefaultView;
DropDownList1.DataValueField = "ProductClassID";
DropDownList1.DataTextField = "ProductClassName";
DropDownList1.DataBind();
}
改一下就可以了,道理一样的!

添加
using System.Data;
using System.Data.OleDb;

......

string strConnection="Provider=Microsoft.Jet.OleDb.4.0;";
strConnection+=@"Data Source=C:\BegASPNET\Northwind.mdb";

OleDbConnection objConnection=new OleDbConnection(strConnection);