Linq to sql增删改查
private void button2_Click(object sender, EventArgs e)//增
{
try
{
Customers ct = new Customers();
ct.CustomerID = "test";
ct.CompanyName = "test";
NorthwindDataContext nc = new NorthwindDataContext();
nc.Customers.InsertOnSubmit(ct);
nc.SubmitChanges();
MessageBox.Show("更新成功");
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
}
}
private void button3_Click(object sender, EventArgs e)//查
{
NorthwindDataContext nt = new NorthwindDataContext();
var a = from s in nt.Customers where s.CustomerID == "test" select new {s.CompanyName,s.ContactName,s.ContactTitle };
foreach (var b in a)
{
MessageBox.Show(b.ToString());
}
}
private void button4_Click(object sender, EventArgs e)//改
{
try
{
NorthwindDataContext nw = new NorthwindDataContext();
var cityNameQuery =
from cust in nw.Customers
where cust.City.Contains("London")
select cust;
foreach (var customer in cityNameQuery)
{
if (customer.City == "London - Metro")
{
customer.City = "London";
}
}
nw.SubmitChanges();
MessageBox.Show("成功");
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
}
}
private void button5_Click(object sender, EventArgs e)//删
{
NorthwindDataContext nw = new NorthwindDataContext();
var a = from s in nw.Customers where s.CustomerID == "jj
相关文档:
最近整理出来的.如果不完全的话希望大家补充.
在access中,转换为大写的sql函数是ucase,在sqlserver中,转换为大写的函数是upper;在access中,转换为小写的函数是lcase,在sqlserver中,转换为小写的函数是lower;在access中,取当前时间的函数是now,另外还有一个取日期函数date,在sqlserver中,取当前的函数是getdate ......
SQL操作全集
下列语句部分是Mssql语句,不可以在access中使用。
SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
首先,简要介绍基础语句:
1、说明:创建数据库
CREA ......
SQL操作全集
下列语句部分是Mssql语句,不可以在access中使用。
SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
首先,简要介绍基础语句:
1、说明:创建数据库
CREATE ......
1.清空日志
DUMP TRANSACTION 库名 WITH NO_LOG
2.截断事务日志:
BACKUP LOG 数据库名 WITH NO_LOG
......