.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
Ïà¹ØÎĵµ£º
Ò»¡¢Ê¹ÓÃSqlConnection¶ÔÏóÁ¬½ÓSQL ServerÊý¾Ý¿â
1¡¢µÇ¼Êý¾Ý¿âµÄ·½Ê½ÎªSQL ServerÑé֤ģʽ
server=·þÎñÆ÷Ãû;database=Êý¾Ý¿âÃû³Æ;uid=Óû§;pwd=ÃÜÂë
2¡¢µÇ¼Êý¾Ý¿âµÄ·½Ê½ÎªWindowsÑé֤ģʽ
server=·þÎñÆ÷Ãû;database=Êý¾Ý¿âÃû³Æ;Integrated Security=SSPI
ÆäÖУ¬Integrated Security¼´Trusted_Connection,È¡Ö ......
Ò»°ãÓÃBCPÔÚ´¦ÀíÕâ¸öÊÂÇ飬µ«ÓÐʱҲÐèÒªÒ»Ð©ÌØÊâµÄ´¦Àí£¬ÒÔÏÂÊÇÉú³É±íÖеÄһЩÊý¾Ý£¬´øÓÐwhereÌõ¼þµÄÑ¡ÔñÉú³ÉÊý¾Ý£¬ÊÇÎÒÒ»¸öͬÊÂÐ޸ĵģ¬Ö±½ÓÄùýÀ´ÓÃÁË£º
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc proc_insert_where (@tablename varchar(256),@where varchar(256 ......
ÔÚ2005ÖÐÓÐͬÒå´ÊÓë¸´ÖÆµÄ¸ÅÄî
ͬÒå´ÊµÄÖ÷Òª×÷ÓÃÊÇ£º
Ò»£ºË޶̶ÔÏóµÄÃû³Æ£¬¼õÉÙ¹¤×÷ÈËÔ±ÊéдµÄʱ¼ä£¬Ìá¸ßЧÂÊ¡£ÎÒÃÇÖªµÀ·ÃÎÊÊý¾Ý¿âÒ»¸ö¶ÔÏóµÄͨ³£×îÈ«µÄ¶ÔÏóÃû³ÆÊÇ£º·þÎñÆ÷Ãû³Æ¡£Êý¾Ý¿âÃû³Æ¡£¼Ü¹¹Ãû³Æ¡£¶ÔÏóÃû³Æ
¶þ£ºÍ¬²½Êý¾Ý¡£ ......
ÄãÊÇ·ñÔÚǧ·½°Ù¼ÆÓÅ»¯SQL Server Êý¾Ý¿âµÄÐÔÄÜ?Èç¹ûÄãµÄÊý¾Ý¿âÖк¬ÓдóÁ¿µÄ±í¸ñ£¬°ÑÕâЩ±í¸ñ·ÖÇø·ÅÈë¶ÀÁ¢µÄÎļþ×é¿ÉÄÜ»áÈÃÄãÊÜÒæ·Ëdz¡£SQL Server 2005ÒýÈëµÄ±í·ÖÇø¼¼Êõ£¬ÈÃÓû§Äܹ»°ÑÊý¾Ý·ÖÉ¢´æ·Åµ½²»Í¬µÄÎïÀí´ÅÅÌÖУ¬Ìá¸ßÕâЩ´ÅÅ̵IJ¢Ðд¦ÀíÐÔÄÜÒÔÓÅ»¯²éѯÐÔÄÜ¡£
¡¡¡¡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 ......