MSDN 解释如下
// Northwnd inherits from System.Data.Linq.DataContext.
Northwnd nw = new Northwnd(@"northwnd.mdf");
// or, if you are not using SQL Server Express
// Northwnd nw = new Northwnd("Database=Northwind;Server=server_name;Integrated Security=SSPI");
var companyNameQuery =
from cust in nw.Customers
where cust.City == "London"
select cust.CompanyName;
foreach (var customer in companyNameQuery)
{
Console.WriteLine(customer);
}
这里我的数据库名称是 Madu,表是 Student,名称、课程和地址。我的编码如下
Madu md = new Madu("Database=Madu;Server=Madu-DV6080;Integrated Security=SSPI");
var courseQuery =from stu in md.Student where stu.Address == "London" select stu.Name;
foreach (var stu in courseQuery)
{
Console.WriteLine(stu);
}
我也添加了“System.Data.Linq”引用。但它给了我一个错误“找不到类型或命名空间名称'Madu'(您是否缺少 using 指令或程序集引用?)”
请帮我。提前谢谢..!