我想用Linq 查询 DataSet里面的一个DataTable 根据条件返回一个 datatable 然后将一个gridview 绑定到新的datatable
我的代码:
public partial class Default2 : System.Web.UI.Page
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void bind()
{
string str = "Data Source=fuhongxia;Initial Catalog=wuyeDataBase;Persist Security Info=True;User ID=sa;Password=123";
SqlConnection conn = new SqlConnection(str);
SqlDataAdapter da = new SqlDataAdapter("select * from house_person", conn);
da.Fill(ds, "house");
dt = ds.Tables["house"].Copy();
this.GridView1.DataSource = dt;
this.GridView1.DataKeyNames = new string[] { "HouseId" };
this.GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
var data = from info in dt.AsEnumerable()
where info.Field<int>("isWork") == 1
select info;
this.GridView2.DataSource = data.CopyToDataTable(); // 提示:数据源中没有 DataRow。
GridView2.DataBind();
}
}看看是什么问题 如果要实现我的那个要求应该如何写? 刚接触LinQ
我的代码:
public partial class Default2 : System.Web.UI.Page
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void bind()
{
string str = "Data Source=fuhongxia;Initial Catalog=wuyeDataBase;Persist Security Info=True;User ID=sa;Password=123";
SqlConnection conn = new SqlConnection(str);
SqlDataAdapter da = new SqlDataAdapter("select * from house_person", conn);
da.Fill(ds, "house");
dt = ds.Tables["house"].Copy();
this.GridView1.DataSource = dt;
this.GridView1.DataKeyNames = new string[] { "HouseId" };
this.GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
var data = from info in dt.AsEnumerable()
where info.Field<int>("isWork") == 1
select info;
this.GridView2.DataSource = data.CopyToDataTable(); // 提示:数据源中没有 DataRow。
GridView2.DataBind();
}
}看看是什么问题 如果要实现我的那个要求应该如何写? 刚接触LinQ
解决方案 »
- 请教:linkbutton传值接值问题?
- 在Gridview的模板里添加了Checkbox控件,并另外添加一个Checkbox控件,实现全选功能与全部删除功能。
- 求一个.net和java中都能用的加密解密算法
- 请大家推荐几本.net入门书籍(顶者有分!)
- 关于.net网站显示html地址
- .net 怎么得到磁盘文件的属性啊?????在线等
- 那位大哥能不能介绍怎么用Nunit工具.要详细的/
- 因为这里聪明人多,所以问一个初等数学问题
- 如何在dataset的tables中动态增加列
- 关于C#操作Excel 资源释放
- 谁做过OA流程,问个问题
- asp.net 胶片效果的图片在DIV中循环不截断播放 大侠请出招急急急
我现在想在GridView1的数据源中 用LinQ 查询符合要求的数据 绑定GridView2Sql语句没有问题
用这句看看翻译出来的SQL有无错