发新话题
打印

[转贴] 如何使用sybase/datawindows( 此文章被查看:231次,被回复:0篇!! )

如何使用sybase/datawindows

使用sybase/datawindows使用AdoTransection访问数据库(sql server2005)

using (SqlConnection theConnection = new SqlConnection())//建立连接
        {
            theConnection.ConnectionString = "Data Source=RICHERS010;" +
                                             "Initial Catalog=testDB_Company;" +
                                             "User ID=sa;Password=sa;" +
                                             "MultipleActiveResultSets=true;";//连接字符串
            theConnection.Open();//打开连接
            AdoTransaction SQLCA = new AdoTransaction(theConnection);//建立事务
            SQLCA.BindConnection();//绑定连接
            WebDataWindowControl1.SetTransaction(SQLCA);//设置事务
            SQLCA.Transaction = SQLCA.Connection.BeginTransaction();//启动事务
            try
            {
                WebDataWindowControl1.UpdateData(true, false);//更新数据
                SQLCA.Transaction.Commit();//提交事务
                WebDataWindowControl1.ResetUpdateStatus();//重置更新状态
                WebDataWindowControl1.Retrieve();//在检索
            }
            catch (DbErrorException DEEx)//捕获数据库异常
            {
                Label1.Text = DEEx.ToString();
                SQLCA.Transaction.Rollback();//回滚事务
            }
            catch (DataWindowNotCreatedException DWNCEx)//捕获无数据窗口异常
            {
                Label1.Text = DWNCEx.ToString();
                SQLCA.Transaction.Rollback();
            }
            catch (InvalidOperationException IOEx)//捕获无效操作数异常
            {
                Label1.Text = IOEx.ToString();
                SQLCA.Transaction.Rollback();
            }
            catch (MethodFailureException MFEx)//捕获方法异常
            {
                Label1.Text = MFEx.ToString();
                SQLCA.Transaction.Rollback();
            }
            finally
            {
                theConnection.Close();//段开连接
            }
        }



© 本文为 ckx0305SCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

发新话题