惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
博客园_首页
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
雷峰网
雷峰网
D
Docker
博客园 - 司徒正美
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
U
Unit 42
J
Java Code Geeks
A
About on SuperTechFans
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security Affairs
I
Intezer
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Tenable Blog
T
Threatpost
H
Hacker News: Front Page
G
Google Developers Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
Lohrmann on Cybersecurity
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
S
Secure Thoughts
GbyAI
GbyAI
NISL@THU
NISL@THU
S
Security @ Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Webroot Blog
Webroot Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - aito

在Umbraco中使用XSLTsearch包实现搜索功能 在Umbraco使用Edit in Cavas(实时编辑器)注意两点 在Umbraco中建立连接列表 在空的Umbraco中建立网页 win 7上安装Umbraco Entity Framework基础:新建一个EF应用 利用VS2010安装的SQL Express2008直接建立数据库文件 新建MCV建立测试工程,编译出错的解决办法 VS中各种文件及其扩展名 MVC学习笔记一:基础知识 分页查询SQL语句 将存储过程用于Command对象 参数化SQL语句 ADO.NET常用对象 ADO.NET简介 jQuery选择器 插入运行代码 - aito - 博客园 Button控件 - aito - 博客园 CSS选择器
ADO.NET事务处理
aito · 2010-08-25 · via 博客园 - aito

事务使一些事件的集合,执行一条SQL语句可以理解成一个事件。事务中包含多个事件,当每一个事件都能执行成功的时候,事务才执行;如果有任何一个事件不能成功执行,事务的其他事件也不被执行。

protected void btnTrans_Click(object sender, EventArgs e)
    {
        OleDbConnection Conn = new OleDbConnection();
        Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
            "Data Source=" + Server.MapPath("person.mdb");
        Conn.Open();
        OleDbCommand Comm = new OleDbCommand();
        OleDbTransaction Trans;
        Trans = Conn.BeginTransaction();
        Comm.Connection = Conn;
        Comm.Transaction = Trans;
        try
        {
            Comm.CommandText = "update grade set 数学=100 where 姓名 like '%齐%'";
            Comm.ExecuteNonQuery();
            Comm.CommandText = "update grade set 数学=60 where 姓名 like '%张%'";
            Comm.ExecuteNonQuery();
            Trans.Commit();
            Response.Write("事务执行成功!");
        }
        catch (Exception ex)
        {
            Trans.Rollback();
            Response.Write("出现错误,事务已经回滚!");
        }
        finally
        {
            Conn.Close();
        }
    }