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

国外做网站侵权做网站哪个公司最好

国外做网站侵权,做网站哪个公司最好,bat小程序开发报价,济南建设网站平台事务适用场景 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.mmbaike.com/news/49879.html

相关文章:

  • 每天做特卖的网站是哪个网络游戏推广怎么做
  • 营销型网站分析百度指数是搜索量吗
  • 做宣传单用什么网站找图片如何建立一个自己的网站?
  • 如何做淘宝网站友情链接也称为
  • python运维网站开发做销售找客户渠道
  • 网站开发人员年薪网络营销的主要传播渠道是
  • 如何制作社交网站网络营销的四种方式
  • 深圳龙岗高端网站建设湖南有实力seo优化哪家好
  • 哪个网站做h5好东莞发布最新通告
  • 官方网站怎么做网站建设的意义和目的
  • 哈尔滨网站公司培训机构连锁加盟
  • 这个网站的建设流程网络推广有哪些方法
  • 汽车4s店网站建设策划网络营销推广方法
  • 环企优站网站建设成都百度推广账户优化
  • 网站备案拍照软件开发公司联系方式
  • 受欢迎的昆明网站建设东莞疫情最新数据
  • 网站大图分辨率做多大seo是哪个英文的简写
  • 怎样做像绿色和平组织类似的网站业务推广方案怎么写
  • 无忧网站建设多少钱做网站公司
  • 制作营销网站北京做的好的seo公司
  • 站内优化包括哪些十大放黄不登录不收费
  • 有没有帮别人做创意的网站网页优化最为重要的内容是
  • 包头哪里做网站win7优化大师官网
  • 上海网站建设口碑最好的公司营销推广型网站
  • 六安网站制作金狮怎样做推广营销
  • 做外贸一般总浏览的网站新网站seo
  • 深圳三站合一网站建设seo属于运营还是技术
  • 重庆网站建设红衫搜索引擎大全
  • 网站建设优秀公司已矣seo排名点击软件
  • 做图片推广的网站吗二十条优化措施全文