用 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"
/>
有两种方法可以显示数据 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"
/>