易截截图软件、单文件、免安装、纯绿色、仅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 Server里sp_helptext输出格式错行问题

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 isnull函数的使用


sql isnull函数的使用
ISNULL
使用指定的替换值替换 NULL。
语法
ISNULL ( check_expression , replacement_value )
参数
check_expression
将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。
replacement_value
在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 chec ......

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语句奥妙之一

例如问题:现在你面对一张表 table1 , table1中有个字段为sales_salary ,在数据库存放的字段为int 类型 。
要求,你统计的结果单位(万元),保留2位小数。并且会有这样的等式 (1行+2行=3行=7行+8行) 面对这样的问题,解决的方案有很多。比如,你可以通过视图的方案来解决,或控制输入域 ...
但有一种等效控制输入 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号