——————c#源程序—————-
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sql" %>
<html>
<script language="c#" runat="server">
protected void page_load(object src, eventargs e)
{
sqlconnection myconnection = new sqlconnection("server=localhost;uid=sa;pwd=;database=pubs");
sqldatasetcommand mycommand = new sqldatasetcommand("select * from authors", myconnection);
dataset ds = new dataset();
mycommand.filldataset(ds, "authors");
mydatagrid.datasource=ds.tables["authors"].defaultview;
mydatagrid.databind();
}
</script>
<body>
<h3><font face="verdana">simple select to a datagrid control</font></h3>
<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"
maintainstate="false"
/>
</body>
</html>
————#vb源程序—————
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sql" %>
<html>
<script language="vb" runat="server">
sub page_load(src as object, e as eventargs)
dim ds as dataset
dim myconnection as sqlconnection
dim mycommand as sqldatasetcommand
myconnection = new sqlconnection("server=localhost;uid=sa;pwd=;database=pubs")
mycommand = new sqldatasetcommand("select * from authors", myconnection)
ds = new dataset()
mycommand.filldataset(ds, "authors")
mydatagrid.datasource=ds.tables("authors").defaultview
mydatagrid.databind()
end sub
</script>
<body>
<h3><font face="verdana">simple select to a datagrid control</font></h3>
<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"
maintainstate="false"
/>
</body>
</html>
