当前位置: 首页 > news >正文

网站建设管理维护责任书格式阿里巴巴友情链接怎么设置

网站建设管理维护责任书格式,阿里巴巴友情链接怎么设置,买了个服务器 怎么做网站,百度小程序可以根据网站的要求做吗事务适用场景 1 事务使用在存储过程中,直接在数据库中进行编写 2 事务使用在Winfrom项目中 SQl:使用事务转账操作的实例 一般都会找一个变量记录错误的个数,error记录上一句sql的错误和错误编号 declare errornum int 0 -- 定义…

事务适用场景

        1 事务使用在存储过程中,直接在数据库中进行编写
        2 事务使用在Winfrom项目中

SQl:使用事务转账操作的实例

一般都会找一个变量记录错误的个数,@error记录上一句sql的错误和错误编号

declare @errornum int  = 0 -- 定义一个记录错误个数的变量
begin transaction -- 开启事务begin-- 转出操作update Card set CurrentMoney = CurrentMoney - 100000 where StudentId = 1002set @errornum = @errornum + @@error -- 把@@error加到总的记录上-- 转入操作update Card set CurrentMoney = CurrentMoney + 100000 where StudentId = 1004set @errornum = @errornum + @@ERRORif(@errornum > 0) -- 证明有错误,把之前已经执行的操作回滚到原先的数据上rollback transaction -- 回滚事务else -- 没有错误,提交事务commit transactionend
go
select * from Card

声明一个过程 包含三个输入参数 分别是两个转账的卡号 和转账的金额

use YinHangDB
go
create procedure tt10000@outZhangHao int,@ruZhangHao int,@Money int
asdeclare @c1 int = 0--错误的个数begin transaction --开启事务begin--转出update Card set CurrentMoney = CurrentMoney - @Money where StudentId = @outZhangHaoset @c1 = @c1 + @@ERROR--转入update Card set CurrentMoney = CurrentMoney + @Money where StudentId = @ruZhangHaoset @c1 = @c1 + @@ERRORif(@c1>0)rollback transactionelse commit transactionendgo	
select * from Card
--测试转账失败的操作
exec tt10000 1000,1001,100000--测试转账成功
exec tt10000 1000,1001,50000

Winfrom 使用事故实例

链接SQl 数据库

public string connString = @"Server=.;Database=SMDB;Uid=sa;Pwd=123456";

搭建Winfrom界面

 测试事务回滚的方法

 private void button1_Click(object sender, EventArgs e){//删除前学生总个数int num1 = (int)GetSingleCount("select count(*) from Students");this.listBox1.Items.Add("删除前学生总个数:"+ num1);  // 展示在listbox下// 测试删除学生失败进行事务回滚操作//定义一个列表字符串 List<string> list = new List<string>(){"delete from Students where StudentId = 1000005","delete from Students where StudentId = 1000024","delete from Students where StudentId = 1000006"};//执行删除操作 把list里面每一句sql都去执行一下int result = 0;try{result = UpdateDataBase(list);}catch (Exception ex){this.listBox1.Items.Add(ex.Message);}if (result > 0){this.listBox1.Items.Add("删除成功");}else{this.listBox1.Items.Add("删除失败");}this.listBox1.Items.Add("删除之后剩余人数为:" + (int)GetSingleCount("select count(*) from Students"));}

封装多个删除语句执行操作
参数是多个sql的集合
返回值 int是否执行成功

public int UpdateDataBase(List<string> list)
{SqlConnection conn = new SqlConnection(connString);//  new SqlCommand(sql, conn)//  没有指定执行sql 没有指定连接,下面必须在写代码把连接对象添加上SqlCommand cmd = new SqlCommand(); cmd.Connection = conn;try{conn.Open();//开启事务cmd.Transaction = conn.BeginTransaction();int result = 0;//记录删除时候受影响的行数//取出每一个sql语句 分别执行foreach (string sql in list){//设置执行的sqlcmd.CommandText = sql; result += cmd.ExecuteNonQuery();// cmd.ExecuteNonQuery() 返回受影响行数如果删除成功了,受影响行数不为0}//如果执行错误了 跳转到catch里面 在catch执行回滚// 没有出错 提交事务cmd.Transaction.Commit();return result;}catch(Exception ex){if (cmd.Transaction != null){cmd.Transaction.Rollback(); // 执行sql语句有错误的情况 执行回滚操作}throw new Exception("执行删除sql事务出错:" + ex.Message);}finally{// 不管是否执行有误 把事务置为null 清除事务if(cmd.Transaction!=null){cmd.Transaction = null;}conn.Close();}
}

获取数据库个数的方法

 public object GetSingleCount(string sql)
 {
     SqlConnection conn = new SqlConnection(connString);
     SqlCommand cmd = new SqlCommand(sql, conn);
     conn.Open();
     return cmd.ExecuteScalar();

 }

测试事务提交的方法 

private void button2_Click(object sender, EventArgs e)
{//删除前学生总个数int num1 = (int)GetSingleCount("select count(*) from Students");this.listBox1.Items.Add("删除前学生总个数:" + num1);  // 展示在listbox下// 测试删除学生失败进行事务回滚操作//定义一个列表字符串 List<string> list = new List<string>(){"delete from Students where StudentId = 1000033","delete from Students where StudentId = 1000031","delete from Students where StudentId = 1000032"};//执行删除操作 把list里面每一句sql都去执行一下int result = 0;try{result = UpdateDataBase(list);}catch (Exception ex){this.listBox1.Items.Add(ex.Message);}if (result > 0){this.listBox1.Items.Add("删除成功");}else{this.listBox1.Items.Add("删除失败");}this.listBox1.Items.Add("删除之后剩余人数为:" + (int)GetSingleCount("select count(*) from Students"));
}

http://www.hrbkazy.com/news/183.html

相关文章:

  • 上海软件网站建设seo对网店推广的作用有哪些
  • 山东省日照市有专业做网站的阿里指数app下载
  • dw中怎样做网站链接网络营销网站推广方案
  • 图片网站怎么做排名兰州疫情最新情况
  • 兰州市做网站的公司搜索引擎推广渠道
  • 做图网站网络营销自学网站
  • 枞阳县建设局网站seo培训一对一
  • 用家里的电脑做网站服务器危机公关处理方案
  • 上饶做网站飞猪关键词排名优化
  • 西安手机网站建设动力无限扬州网络优化推广
  • 河南省建设厅地址南宁网站seo外包
  • dw怎么导入网站模板百度下载链接
  • 网站被做301跳转了怎么办网络媒体推广报价
  • 餐饮网站开发毕业设计模板南京seo公司教程
  • wordpress登录qq湖南竞价优化专业公司
  • 网站开发需要经过的几个主要阶段太原百度搜索排名优化
  • 旅游网站建设的摘要培训机构排名全国十大教育机构排名
  • 国际设计师网站有哪些网站推广方案模板
  • #NAME?黑帽seo教程
  • 做网站ui去哪儿接私活郑州网站推广公司哪家好
  • 北京seo网站内部优化免费影视软件靠什么赚钱
  • 网站app有哪些功能2021年关键词排名
  • 上海网站建设企天津关键词优化网排名
  • 上海app网络推广公司电话5年网站seo优化公司
  • postgresql做网站用什么环境网站seo优化是什么意思
  • 石家庄网站定做网络营销代运营外包公司
  • 电脑课要求的网站怎么做百度seo排名培训
  • 建设一个大型网站大概费用企业网站优化排名
  • 手机网站开发框架企业培训课程表
  • 阿里巴巴做企业网站西安网站建设公司十强