.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交驻报表查询问题,欢迎各位指教!
我想把图1的使用信息,使用SQL语句,实现如图2的结果。
表名
序号
字段名
a
1
c
a
2
d
a
3
e
a
4
f
a
5
g
b
1
h
b
2
i
b
3
j
b
4
k
b
5
l
c
1
m
c
2
n
c
3
o
c
4
p
c
5
q
图1
表名
序号
1
2
3
4
5
......
use Master
go
if object_id('SP_SQL') is not null
drop proc SP_SQL
go
create proc [dbo].[SP_SQL](@ObjectName sysname)
as
set nocount on ;
declare @Print varchar(max)
if exists(select 1 from syscomments where ID=objec ......
你是否在千方百计优化SQL Server 数据库的性能?如果你的数据库中含有大量的表格,把这些表格分区放入独立的文件组可能会让你受益匪浅。SQL Server 2005引入的表分区技术,让用户能够把数据分散存放到不同的物理磁盘中,提高这些磁盘的并行处理性能以优化查询性能。
SQL Server数据库表分区操作过程由三个步骤组成:
� ......
1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)
法一:select * into b from a where 1 <>1
法二:select top 0 * into b from a
2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)
insert into b(a, b, c) select d,e,f from b;
3、说明:跨数据库之间表的拷贝(具体数据使用 ......