ASP.NET入门教程 ASP.NET操作数据库(3)

发布时间:2007年08月19日      浏览次数:766 次
用 DataReader 方法显示数据
  有两种方法可以显示数据 DataReader方法,和DataSet方法,而DataReader只能储存查询数据,我们先讲用DataReader方法显示
<script language="VB" runat="server">
 Sub Page_Load(Src As Object, E As EventArgs)
  Dim MyConnection As SQLConnection =
     New SQLConnection("server=localhost;uid=sa;
               pwd=;database=aspnet")
  Dim MyCommand As SQLCommand =
     New SQLCommand("select * from User", MyConnection)
  MyConnection.Open()
  Dim DR As SQLDataReader
  MyCommand.Execute(DR)
  MyDataGrid.DataSource = DR
  MyDataGrid.DataBind()
  MyConnection.Close()
 End Sub
</script>
<ASP:DataGrid id="MyDataGrid" runat="server"
   Width="700"
   BackColor="#ccccff"
   BorderColor="black"
   ShowFooter="false"
   CellPadding=3
   CellSpacing="0"
   Font-Name="Verdana"
   Font-Size="8pt"
   HeaderStyle-BackColor="#aaaadd"
/>
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!