如何在没有Gridview的情况下使用ASP.NET从数据库获取数据

时间:2016-09-28 20:50:24

标签: c# sql asp.net

我是ASP.NET的新手,我一直在尝试从数据库中获取数据以显示在我的动态网页上,以便从数据库中获取[first_name], [weight_data] and [date]

我一直在浏览文档,所有我看到的是Gridview教程,如何从数据库中获取SELECT [first_name] FROM [userData] WHERE id='1的值只显示first_name字符串而没有别的?

谢谢。

<%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="Web_Portal_Final.About" %>

    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
        <h2><%: Title %>.</h2>
        <h3>This is where your data goes</h3>
        <p>Once the app can record data, this will be set.</p>
        <p>Hi, [first_name] Your weight is [weight_data]. This was taken on [date].</p>
        <asp:GridView runat="server" AutoGenerateColumns="False" EmptyDataText="There are no data records to display." DataSourceID="SqlDataSource2"><Columns>
    <asp:BoundField DataField="first_name"></asp:BoundField>
    </Columns>
    </asp:GridView>
     <asp:SqlDataSource runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" ProviderName="<%$ ConnectionStrings:DefaultConnection.ProviderName %>" SelectCommand="SELECT [first_name] FROM [userData] WHERE id='1'" ID="SqlDataSource2"></asp:SqlDataSource>
        <br />
    </asp:Content>

0 个答案:

没有答案