盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

ASP+中执行容易的Select查询,并返回数据表到DataGrid源

时间:2024/9/29作者:未知来源:盾怪网教程人气:

[摘要]------------------c#源程序---------------- <%@ Import Namespace="System.Data" %> <%...

------------------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>
(出处:热点网络)

关键词:ASP+中执行容易的Select查询,并返回数据表到DataGrid源




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版