Visual Studio 2008之新特性LINQ(二)
2008-05-19 10:42
330 查看
我们来编写一个selectTable()方法用来查询Myuser表,
ADO.NET:
private void SelectTable()
...{
this.comm = new SqlCommand();
this.comm.Connection = this.conn;
this.comm.CommandType = CommandType.Text;
this.comm.CommandText = "select * from MyUser";
DataSet ds = new DataSet();
this.da = new SqlDataAdapter();
this.da.SelectCommand = this.comm;
this.da.Fill(ds);
this.dvShow.DataSource = ds.Tables[0].DefaultView;
this.dvShow.DataBind();
}
LINQ:
private void SelectTable()
...{
DataAccessDataContext ddc = new DataAccessDataContext();
var select = from user in ddc.MyUsers
select user;
this.dvShow.DataSource = select;
this.dvShow.DataBind();
}
大家可以看得很清楚了,使用LINQ极大地减少了代码编写的量,并且不再需要程序员编写SQL语句,处理起数据库操作就更加得心应手了。
LINQ架构
LINQ的查询关键字:
-from
-where
-select
-group
-into
-orderby
-join
-let
与SQL语句的关键字多相似啊,相信大家通过一定时间的练习应该能很好的掌握。
ADO.NET:
private void SelectTable()
...{
this.comm = new SqlCommand();
this.comm.Connection = this.conn;
this.comm.CommandType = CommandType.Text;
this.comm.CommandText = "select * from MyUser";
DataSet ds = new DataSet();
this.da = new SqlDataAdapter();
this.da.SelectCommand = this.comm;
this.da.Fill(ds);
this.dvShow.DataSource = ds.Tables[0].DefaultView;
this.dvShow.DataBind();
}
LINQ:
private void SelectTable()
...{
DataAccessDataContext ddc = new DataAccessDataContext();
var select = from user in ddc.MyUsers
select user;
this.dvShow.DataSource = select;
this.dvShow.DataBind();
}
大家可以看得很清楚了,使用LINQ极大地减少了代码编写的量,并且不再需要程序员编写SQL语句,处理起数据库操作就更加得心应手了。
LINQ架构
LINQ的查询关键字:
-from
-where
-select
-group
-into
-orderby
-join
-let
与SQL语句的关键字多相似啊,相信大家通过一定时间的练习应该能很好的掌握。
相关文章推荐
- Visual Studio 2008开发新特性系列课程(3):VS2008新特性之LINQ入门
- Visual Studio 2008开发新特性系列课程(4):VS2008新特性之LINQ实战
- LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性
- Visual Studio 2008开发新特性系列课程(4):VS2008新特性之LINQ实战
- LINQ体验(1)——Visual Studio 2008新特性
- [转]LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性
- Visual Studio 2008之新特性LINQ(一)
- LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性
- Visual Studio 2008之新特性LINQ(三)之LINQ To Object查询
- LINQ体验(1)——Visual Studio 2008新特性
- LINQ体验(1)——Visual Studio 2008新特性