在ADO.NET中如何返回多表联合查询的结果?

xingming_sun 2002-06-11 03:02:09
在ADO中可以很方便的将联合查询的结果放在记录集中。
而在ADO.NET中没有记录集了,如果我想将通过一个联合查询得到的记录集显示
在网格控件中,该如何实现呢?
...全文
146 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2002-06-11
  • 打赏
  • 举报
回复
you can use DataReader, here is an example from .Net quickstart tutorial:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="C#" runat="server">

protected void Page_Load(Object sender, EventArgs e) {
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");
SqlCommand myCommand = new SqlCommand("select * from Authors", myConnection); //put your query here

myConnection.Open();

SqlDataReader dr = myCommand.ExecuteReader();

MyDataGrid.DataSource = dr;
MyDataGrid.DataBind();

myConnection.Close();
}

</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"
EnableViewState="false"
/>

</body>
</html>
saucer 2002-06-11
  • 打赏
  • 举报
回复
you can use DataReader, here is an example from .Net quickstart tutorial:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="C#" runat="server">

protected void Page_Load(Object sender, EventArgs e) {
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");
SqlCommand myCommand = new SqlCommand("select * from Authors", myConnection); //put your query here

myConnection.Open();

SqlDataReader dr = myCommand.ExecuteReader();

MyDataGrid.DataSource = dr;
MyDataGrid.DataBind();

myConnection.Close();
}

</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"
EnableViewState="false"
/>

</body>
</html>
yellowwee 2002-06-11
  • 打赏
  • 举报
回复
在把它绑定到DataGrid中就可以显示了!
yellowwee 2002-06-11
  • 打赏
  • 举报
回复
你把用SQL语句查询出的值fill到DataSet中就可以了,ado.net使用DataSet来储存记录集!

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧