| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 561 人关注过本帖
标题:.net事务处理!求助!!!!
只看楼主 加入收藏
fhqvj871113
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-8-2
收藏
 问题点数:0 回复次数:0 
.net事务处理!求助!!!!
本人想处理事务删除两个相关表中的内容,但以下代码会自动产生异常直接抛出,希望各位高手可以帮忙,谢谢
(存储过程没有问题,在没加事务之前正常删除过表中内容)


添加引用dll内容

      
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace Group_ComputerInformation
{
    public class Student_Computer
    {        
        private static string connectiondatabase = @"Server= 192.168.151.174;User=sa;PWD=000000 ;Database = StudentManagement;";
        /// <summary>
        /// 删除表Student_OperationSystem中的信息,需先删除与之相关表中内容,此过程为删除相关表的内容
        /// </summary>
        /// <param name="operationsystem_ID">删除条件参数</param>
        public void OS_delete_ComputerInformation(SqlConnection database,int operationsystem_ID)
        {
            SqlCommand cmd = new SqlCommand("OS_delete_ComputerInformation",database);
             = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@OperationSystem_ID", SqlDbType.Int);
            cmd.Parameters["@OperationSystem_ID"].Value = operationsystem_ID;
            cmd.ExecuteNonQuery();
        }
        /// <summary>
        /// 删除表Student_OperationSystem中的信息,删除过相关表后,才执行次过程
        /// </summary>
        /// <param name="operationsystem_ID">删除条件参数</param>
        public void OS_delete_OperationSystem(SqlConnection database,int operationsystem_ID)
        {
            SqlCommand cmd = new SqlCommand("OS_delete_OperationSystem",database);
             = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@ID", SqlDbType.Int);
            cmd.Parameters["@ID"].Value = operationsystem_ID;
            cmd.ExecuteNonQuery();
        }
        /// <summary>
        /// 删除表Student_OperationSystem中内容的事务处理
        /// </summary>
        /// <param name="operationsystem_ID"></param>
        public void TS_OS_delete_OperationSystem(int operationsystem_ID)
        {

            SqlConnection database = new SqlConnection(connectiondatabase);
            database.Open();
            SqlTransaction sqlTran = database.BeginTransaction();            
            SqlCommand command = database.CreateCommand();
            command.Connection = database;
            command.Transaction = sqlTran;
            try
            {
                OS_delete_ComputerInformation(database,operationsystem_ID);
                OS_delete_OperationSystem(database,operationsystem_ID);               
                ();
            }
            catch (Exception ex)
            {
                sqlTran.Rollback();
            }
            finally
            {
                database.Close();
            }
        }
}
搜索更多相关主题的帖子: 事务处理 
2008-08-02 19:43
快速回复:.net事务处理!求助!!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035483 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved