In ASP.NET, what is the definitive way to pull one record from the database and bind it and HTML tag? Brevity and style points count.
A:
For brevity, you'll want to use the SqlDataSource.
<asp:SqlDataSource ID="sql" runat="server" ConnectionString='<%$ ConnectionStrings:MyConnectionString %>'
SelectCommandType="Text"
SelectCommand="select MyField FROM MyTable WHERE ID = @id"
>
<SelectParameters>
<asp:ControlParameter ControlID="txtUserName" PropertyName="Text" Name="id" />
</SelectParameters>
</asp:SqlDataSource>
<asp:BulletedList runat="server" DataTextField="MyField" DataSourceID="sql">
</asp:BulletedList>
Babak Naffas
2009-07-23 20:57:09
How about in the code behind?
mmcglynn
2009-07-24 14:05:40
A:
It's not clear what you want but, detailsview control is designed for displaying only one record from data source.
DetailsView is a data-bound user interface control that renders a single record at a time from its associated data source, optionally providing paging buttons to navigate between records.
Canavar
2009-07-24 14:07:22