<!-- <%@ Page Trace="True" %> -->
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Html>
<Body BgColor="White">
<H3>使用 ADO+, 结合 DataGrid -- ado+.aspx <HR></H3>
<asp:DataGrid HeaderStyle-BackColor="Cyan" id="Grid1" runat="server"/>
</Body>
</Html>
<script Language="VB" runat="server">
Sub Page_Load(Src As Object, e As EventArgs)
Grid1.DataSource = CreateDataView( "pubs", "Authors" )
Grid1.DataBind()
End Sub
Function CreateDataView( Db As String, Table As String ) As DataView
Dim ConnStr, SQL As String
ConnStr = "server=hnby-dom;uid=sa;pwd=;database="&Db
Dim Conn As SqlConnection
Dim Cmd As SqlDataAdapter
Conn = new SqlConnection(ConnStr)
Cmd = New SqlDataAdapter( "Select * from " & Table, ConnStr )
Dim ds As DataSet = new DataSet()
Cmd.Fill(ds, Table)
CreateDataView = new DataView(ds.Tables(Table))
End Function
</script>
和使用ADO+(一)不同,这里用到一个函数CreateDataView,你可以单独吧这个函数做到一个包含页面里。
------------------------------------------------
以上在win2000server,win2000professional,sql6.0,Microsoft .NET Framework SDK beta2测试通过。
实例:http://202.102.247.235/aspx/ado2.aspx