asp.net ,在vs2005中添加了一个DataList,如何绑定数据库中的数据?
- 提问者网友:王者佥
- 2021-06-02 07:13
- 五星知识达人网友:千杯敬自由
- 2021-06-02 07:47
如果你学过datagrid,datagridview等,那么就都是一个样子的,我没用过ACCESS但是应该跟sqlserver、Oracle没什么区别,无非制定数据源,绑定数据源,关键是你里面要绑定你要绑定的这个字段呗,
然后你在源码里这样写
<asp:ID="Label1" runat="server" Text='<%#Eval("edit_title")%'>这样就行了
- 1楼网友:千杯敬自由
- 2021-06-02 07:54
首先 查询Access数据库 例如
后台:
string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" + Server.MapPath(xxxx.asa); string strCommandText = Commandtext; OleDbConnection myConnection = new OleDbConnection(strConnection); myConnection.Open(); OleDbDataAdapter myAdpater = new OleDbDataAdapter("select edit_title from edit",myConnection); OleDbCommandBuilder myBuilder = new OleDbCommandBuilder(myAdpater); DataSet myDataset = new DataSet(); myAdpater.Fill(myDataset); myConnection.Close();
//设置DataList数据源
this.DataList1.DataSource=myDataSet;
this.DataList1.DataBind();
页面:
<asp:Label ID="label1" runat="server" Text='<%#Eval("edit_title")'%>