我这里提供了一些数据库连接的代码
string ds=ConfigurationSettings.AppSettings["Systen"];
SqlConnection myConnection=new SqlConnection(ds);
SqlCommand SelectCommand;
SelectCommand=new SqlCommand("select category from News_category_table");
SelectCommand.Connection=myConnection;
myConnection.Open();
SqlDataReader myred=SelectCommand.ExecuteReader();
string ds=ConfigurationSettings.AppSettings["Systen"];
SqlConnection myConnection=new SqlConnection(ds);
SqlCommand SelectCommand;
SelectCommand=new SqlCommand("select category from News_category_table");
SelectCommand.Connection=myConnection;
myConnection.Open();
SqlDataReader myred=SelectCommand.ExecuteReader();
SqlConnection myConnection=new SqlConnection(ds); SqlDataAdapter sda = new SqlDataAdapter("select category from News_category_table",myConnection);
DataTable dt = new DataTable();
sda.Fill(dt);
this.DataList1.DataSource = dt;
this.DataList1.DataBind();
string ds=ConfigurationSettings.AppSettings["Systen"];
SqlConnection myConnection=new SqlConnection(ds);
SqlCommand SelectCommand;
SelectCommand=new SqlCommand("select category from News_category_table");
SelectCommand.Connection=myConnection;
myConnection.Open();
SqlDataReader myred=SelectCommand.ExecuteReader(); =====
如果不想分页,那就直接让datalist的datasource=myred;如果想分页,那就用dataset配合sqldataadapter填充。
<asp:DataList id="DataList1" runat="server" Height="146px">
<ItemTemplate>
<TABLE id="Table1" width="300">
<TR>
<TD> <asp:LinkButton id=LinkButton1 runat="server" Width="282px" Text='<%# DataBinder.Eval(Container, "DataItem.category") %>'>
</asp:LinkButton>
</TD>
</TR>
</TABLE>
<FONT face="宋体"></FONT>
</ItemTemplate>
<AlternatingItemTemplate>
<FONT face="宋体"></FONT>
</AlternatingItemTemplate>
</asp:DataList></FONT></td>