易截截图软件、单文件、免安装、纯绿色、仅160KB

.NET学习手记之:linq to SQL(一)


一个简单的例子:
先建一个C#类:
引用System.Data.Linq.dll程序集,
using System.Data.Linq.Mapping和
using System.Data.Linq 两个空间。
[Table]
public class Inventory
{
   [Column]
   public string Make;
   [Column]
   public string Color;
   [Column]
   public string PetName;
  
   //指明主键。
   [Column(IsPrimaryKey = true)]
   public int CarID;
  
   public override string ToString()
   {
       return string.Format(
        "编号={0};制造商={1};颜色={2};爱称={3}",
         CarID,Make.Trim(),Color.Trim(),PetName.Trim());
   }
}
与SQL(express版)数据库交互:
class Program
{
   const string cnStr=
       @"Data Source=(local)\SQLEXPRESS;Initial Catalog=Autolot;"+
            "Integrated Security=True";
   static void Main(string[] args)
   {
       Console.WriteLine("*****LINQ to SQL 简单应用*****");
       //创建一个DataContext对象。
       DataContext db= new DataContext(cnStr);
       //创建一个Table<>泛型实例。
       Table<Inventory> invTable = db.GetTable<Inventory>();
       //用一个LINQ查询显示结果。
       foreach(var car in from c in invTable select c)
           Console.WriteLine(car.ToString());
   }
   Console.ReadLine();
}
对DataContext类进行扩展:
class MyAutoLotDatabase:DataContext
{
   public Table<Inventory> Inventory;
   public MyAut


相关文档:

发表一款SQL字符串的简繁体函数

簡體數據庫轉繁體數據庫的問題 拜托了
ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE DatabaseName COLLATE Chinese_Taiwan_Stroke_CI_AS
ALTER DATABASE DatabaseName SET MULTI_USER WITH ROLLBACK ......

循序渐进讲解SQL查询语句高级应用技巧

一、 简单查询
简单的Transact-SQL查询只包括选择列表、from子句和WHERE子句。它们分别说明所查询列、查询的
表或视图、以及搜索条件等。
例如,下面的语句查询testtable表中姓名为“张三”的nickname字段和email字段。
SELECT nickname,email
from testtable
WHERE name='张三'
 
(一) 选择 ......

sql server 定义主键

drop table father;
create table father(
 id int identity(1,1) primary key,
 name varchar(20) not null,
 age int not null
  
)
drop table mother;
create table mother(
 id int identity(1,1),
 name varchar(20) not null,
 age int not null,
 husban ......

sql查询练习

例 34  找出年龄超过平均年龄的学生姓名。
SELECT SNAME
from STUDENTS
WHERE AGE >
      (SELECT  AVG(AGE)
        from   STUDENTS)
例 35  找出各课程的平均成绩,按课程号分组,且只选择学生超过 3 人的课程的成 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号