8,497
社区成员
发帖
与我相关
我的任务
分享
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvOne" runat="server"></asp:GridView>
<asp:GridView ID="gvTwo" runat="server"></asp:GridView>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.Linq;
using System.Data.Linq.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SqlConnection con = new SqlConnection("server=.;uid=xxx;pwd=xxx;database=Northwind"))
{
SqlDataAdapter da = new SqlDataAdapter("select top 5 * from Orders ", con);
DataSet ds = new DataSet();
da.Fill(ds, "Orders");
gvOne.DataSource = ds.Tables["Orders"];
gvOne.DataBind();
}//end using block
NorthwindDataClassesDataContext n = new NorthwindDataClassesDataContext("server=.;uid=xxx;pwd=xxx;database=Northwind");
var custQuery = (from cust in n.Orders orderby cust.OrderID select cust).Take(5);
gvTwo.DataSource = custQuery;
gvTwo.DataBind();
}
}
}