我爱Aspx >> Asp.Net >> C# 3.0新特性初步研究 Part6:使用查询表达式查询表达式(Query Expression)
大家都应该对SQL语句不陌生吧,在C# 2.0之前,嵌入到代码中的SQL就是下面这个样子:
1public void Test()
2{
3SqlConnection c = new SqlConnection(…);
4 c.Open();
5 SqlCommand cmd = new SqlCommand(
6 @“SELECT c.Name, c.Phone // queries in quotes
7 FROM Customers c
8 WHERE c.City = @p0”
9 );
10 cmd.Parameters[“@po”] = “London”; // arguments loosely bound
11 DataReader dr = c.Execute(cmd);
12 while (dr.Read()) {
13 string name = r.GetString(0);
14 string phone = r.GetString(1); // results loosely typed
15 DateTime date = r.GetDateTime(2); // compiler can’t help catch mistakes
16 }
17 r.Close();
18}
在C# 3.0中,我们可以将“SQL语句”方便的运用到其他地方,当然这里并不是真正的SQL语句~~
我觉得我会在以后的开发过程中使用很多以下的类似代码:
1class Program
2 {
3 static void Main(string[] args)
Ҷƪл˵?
C# 3.0新特性初步研究 Part5:匿名..[08-01]
C# 3.0新特性初步研究 Part4:使用..[08-01]
C# 3.0新特性初步研究 Part3:使用..[08-01]
C# 3.0新特性初步研究 Part2:使用..[08-01]
C# 3.0新特性初步研究 Part1:使用..[08-01]
C# 中启动进程的三种方法[08-01]
讲述c#中的类型转换[08-01]
C#简单命名指南[08-01]
在dotnet下用c#编写下载器[08-01]
asp.net中XML文件作为中间件进行..[08-01]
C# 3.0新特性初步研究 Part5:匿名..[08-01]
C# 3.0新特性初步研究 Part4:使用..[08-01]
C# 3.0新特性初步研究 Part3:使用..[08-01]
C# 3.0新特性初步研究 Part2:使用..[08-01]
C# 3.0新特性初步研究 Part1:使用..[08-01]
在Access中模拟sql server存储过..[08-01]
Photoshop 打造转转风车动画[08-01]
photoshop教程:用两个水果做酷酷..[08-01]
PowerPoint中制作倒影艺术字[08-01]
装个小插件 通过GMail远程控制电..[08-01]