当前位置: 首页>>代码示例>>C#>>正文


C# FbConnection.BeginTransaction方法代码示例

本文整理汇总了C#中FirebirdSql.Data.FirebirdClient.FbConnection.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# FbConnection.BeginTransaction方法的具体用法?C# FbConnection.BeginTransaction怎么用?C# FbConnection.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FirebirdSql.Data.FirebirdClient.FbConnection的用法示例。


在下文中一共展示了FbConnection.BeginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InsertTestData

        private static void InsertTestData(string connectionString)
        {
            FbConnection connection = new FbConnection(connectionString);
            connection.Open();

            StringBuilder commandText = new StringBuilder();

            commandText.Append("insert into	test (int_field, char_field, varchar_field,	bigint_field, smallint_field, float_field, double_field, numeric_field,	date_field,	time_field,	timestamp_field, clob_field, blob_field)");
            commandText.Append(" values(@int_field,	@char_field, @varchar_field, @bigint_field,	@smallint_field, @float_field, @double_field, @numeric_field, @date_field, @time_field,	@timestamp_field, @clob_field, @blob_field)");

            FbTransaction transaction = connection.BeginTransaction();
            FbCommand command = new FbCommand(commandText.ToString(), connection, transaction);

            try
            {
                // Add command parameters
                command.Parameters.Add("@int_field", FbDbType.Integer);
                command.Parameters.Add("@char_field", FbDbType.Char);
                command.Parameters.Add("@varchar_field", FbDbType.VarChar);
                command.Parameters.Add("@bigint_field", FbDbType.BigInt);
                command.Parameters.Add("@smallint_field", FbDbType.SmallInt);
                command.Parameters.Add("@float_field", FbDbType.Double);
                command.Parameters.Add("@double_field", FbDbType.Double);
                command.Parameters.Add("@numeric_field", FbDbType.Numeric);
                command.Parameters.Add("@date_field", FbDbType.Date);
                command.Parameters.Add("@time_Field", FbDbType.Time);
                command.Parameters.Add("@timestamp_field", FbDbType.TimeStamp);
                command.Parameters.Add("@clob_field", FbDbType.Text);
                command.Parameters.Add("@blob_field", FbDbType.Binary);

                command.Prepare();

                for (int i = 0; i < 100; i++)
                {
                    command.Parameters["@int_field"].Value = i;
                    command.Parameters["@char_field"].Value = "IRow " + i.ToString();
                    command.Parameters["@varchar_field"].Value = "IRow Number " + i.ToString();
                    command.Parameters["@bigint_field"].Value = i;
                    command.Parameters["@smallint_field"].Value = i;
                    command.Parameters["@float_field"].Value = (float)(i + 10) / 5;
                    command.Parameters["@double_field"].Value = Math.Log(i, 10);
                    command.Parameters["@numeric_field"].Value = (decimal)(i + 10) / 5;
                    command.Parameters["@date_field"].Value = DateTime.Now;
                    command.Parameters["@time_field"].Value = DateTime.Now;
                    command.Parameters["@timestamp_field"].Value = DateTime.Now;
                    command.Parameters["@clob_field"].Value = "IRow Number " + i.ToString();
                    command.Parameters["@blob_field"].Value = Encoding.Default.GetBytes("IRow Number " + i.ToString());

                    command.ExecuteNonQuery();
                }

                // Commit transaction
                transaction.Commit();
            }
            catch (FbException)
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                command.Dispose();
                connection.Close();
            }
        }
开发者ID:kingpong,项目名称:NETProvider,代码行数:65,代码来源:TestsBase.cs

示例2: BeginTrasactionTest

		public void BeginTrasactionTest()
		{
			string connectionString = this.BuildConnectionString();

			FbConnection conn01 = new FbConnection(connectionString);
			conn01.Open();
			FbTransaction txn01 = conn01.BeginTransaction(IsolationLevel.Unspecified);
			txn01.Rollback();
			conn01.Close();

			FbConnection conn02 = new FbConnection(connectionString);
			conn02.Open();
			FbTransaction txn02 = conn02.BeginTransaction(IsolationLevel.ReadCommitted);
			txn02.Rollback();
			conn02.Close();

			FbConnection conn03 = new FbConnection(connectionString);
			conn03.Open();
			FbTransaction txn03 = conn03.BeginTransaction(IsolationLevel.ReadUncommitted);
			txn03.Rollback();
			conn03.Close();

			FbConnection conn04 = new FbConnection(connectionString);
			conn04.Open();
			FbTransaction txn04 = conn04.BeginTransaction(IsolationLevel.RepeatableRead);
			txn04.Rollback();
			conn04.Close();

			FbConnection conn05 = new FbConnection(connectionString);
			conn05.Open();
			FbTransaction txn05 = conn05.BeginTransaction(IsolationLevel.Serializable);
			txn05.Rollback();
			conn05.Close();
		}
开发者ID:masroore,项目名称:Firebird-NETProvider,代码行数:34,代码来源:FbConnectionTests.cs

示例3: abrir

 public static bool abrir()
 {
     conexao = new FbConnection(stringConexao);
     conexao.Open();
     transacao = conexao.BeginTransaction();
     return true;
 }
开发者ID:Artenes,项目名称:frogi-os,代码行数:7,代码来源:Conexao.cs

示例4: Add

        internal static void Add(MovieInfo movieInfo)
        {
            string commandText = @"INSERT INTO MOVIE_DATA (
                                    LOCATION, FILE_DATA_X, FILE_DATA_Y, FILE_DATA_DURATION, RAW_TITLE_PATH)
                                    VALUES (@location, @file_data_x, @file_data_y, @file_duration, @raw_title_path)";

            using (FbConnection connection = new FbConnection (string.Format (CONNECTION_STRING_FORMAT_FIREBIRD, DB_FILENAME)))
            {
                connection.Open ();

                using (FbTransaction transaction = connection.BeginTransaction ())
                {
                    using (FbCommand cmd = new FbCommand (commandText, connection, transaction))
                    {
                        cmd.Parameters.Add (new FbParameter ("@location", movieInfo.DvdName));
                        cmd.Parameters.Add (new FbParameter ("@file_data_x", movieInfo.FileData.X));
                        cmd.Parameters.Add (new FbParameter ("@file_data_y", movieInfo.FileData.Y));
                        cmd.Parameters.Add (new FbParameter ("@file_duration", movieInfo.FileData.Duration));
                        cmd.Parameters.Add (new FbParameter ("@raw_title_path", movieInfo.RawTitlePath));

                        cmd.ExecuteNonQuery ();
                    }
                    transaction.Commit ();
                }
            }
        }
开发者ID:AZiegler71,项目名称:DVD-Sammlung,代码行数:26,代码来源:MoviePersistence.cs

示例5: check_func

 public static bool check_func(FbConnectionStringBuilder fc)
 {
     bool res_ = false;
     using (FbConnection fb = new FbConnection(fc.ConnectionString))
     {
         try
         {
             fb.Open();
             using (FbTransaction ft = fb.BeginTransaction())
             {
                 using (FbCommand fcon = new FbCommand(sql_func,fb,ft))
                 {
                     using (FbDataReader fr = fcon.ExecuteReader())
                     {
                         while (fr.Read())
                         {
                             res_ = true;
                         }
                         fr.Dispose();
                     }
                     fcon.Dispose();
                 }
                 ft.Commit();
                 ft.Dispose();
             }
         }
         catch { }
         finally { fb.Close(); }
         fb.Dispose();
     }
     return res_;
 }
开发者ID:nigihayami,项目名称:dataPump2.det,代码行数:32,代码来源:Check_.cs

示例6: execute

        public override void execute(Options options, INIManager iniManager)
        {
            string AppKey = iniManager.IniReadValue("APP", "AppKey");
            string AppSecret = iniManager.IniReadValue("APP", "AppSecret");
            string TaobaoAsistantPath = iniManager.IniReadValue("淘宝助理", "安装目录");

            string nick = options.Nick;
            string SessionKey = iniManager.IniReadValue(nick, "SessionKey");

            string userId = iniManager.IniReadValue(nick, "UserId");
            if (userId == null || userId.Trim().Equals(""))
            {
                userId = "1696293148";
            }

            StreamWriter MovePicLogWriter;

            FileStream MovePicLog = new FileStream(Environment.CurrentDirectory + "\\" + "MovePic.log", FileMode.Append);
            MovePicLogWriter = new StreamWriter(MovePicLog, Encoding.Default);
            FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
            cs.Database = Path.Combine(TaobaoAsistantPath, "users\\" + nick + "\\APPITEM.DAT");
            cs.Charset = "UTF8";
            cs.UserID = "SYSDBA";
            cs.Password = "masterkey";
            cs.ServerType = FbServerType.Embedded;
            FbConnection fbCon = new FbConnection(cs.ToString());
            fbCon.Open();

            FbCommand ItemsCommand = null;
            ItemsCommand = new FbCommand("SELECT * FROM ITEM WHERE OUTER_ID = @SearchString OR TITLE = @SearchString", fbCon);
            FbParameter SearchString = new FbParameter("@SearchString", FbDbType.VarChar);
            SearchString.Value = options.Item;
            ItemsCommand.Parameters.Add(SearchString);

            FbDataReader ItemsReader = ItemsCommand.ExecuteReader();
            while (ItemsReader.Read())
            {
                MovePicLogWriter.WriteLine("--------------------------------------------------------------------------------");
                Console.WriteLine("--------------------------------------------------------------------------------");
                string ClientID = ItemsReader["CLIENT_ID"].ToString();
                string Title = ItemsReader["TITLE"].ToString();
                Console.WriteLine("ClientID=" + ClientID);
                MovePicLogWriter.WriteLine("ClientID=" + ClientID);
                Console.WriteLine("TITLE=" + Title);

                MovePicLogWriter.WriteLine("TITLE=" + Title);
                FbTransaction myTransaction = fbCon.BeginTransaction();
                FbCommand DeleteCommand = new FbCommand("UPDATE ITEM SET CLIENT_IS_DELETE = 1 WHERE CLIENT_ID = @ClientID", fbCon);
                FbParameter ParamID = new FbParameter("@ClientID", FbDbType.VarChar);
                ParamID.Value = ClientID;
                DeleteCommand.Parameters.Add(ParamID);
                DeleteCommand.Transaction = myTransaction;
                DeleteCommand.ExecuteNonQuery();
                myTransaction.Commit();
            }
            fbCon.Close();
            MovePicLogWriter.Close();
            MovePicLog.Close();
        }
开发者ID:kldcty,项目名称:movepic,代码行数:59,代码来源:DeleteItem.cs

示例7: BeginTransactionNoWaitTimeoutTest

		public void BeginTransactionNoWaitTimeoutTest()
		{
			using (FbConnection conn = new FbConnection(this.BuildConnectionString()))
			{
				conn.Open();
				FbTransaction tx = conn.BeginTransaction(new FbTransactionOptions() { WaitTimeout = null });
				Assert.NotNull(tx);
				tx.Rollback();
			}
		}
开发者ID:cafee,项目名称:NETProvider,代码行数:10,代码来源:FbConnectionTests.cs

示例8: DatabaseCommand

 public static void DatabaseCommand(string command)
 {
     FbConnection con = new FbConnection(ConStr.ConnectionString);
     con.Open();
     FbTransaction transaction = con.BeginTransaction();
     FbCommand com = new FbCommand(command, con, transaction);
     com.ExecuteNonQuery();
     transaction.Commit();
     con.Close();
 }
开发者ID:GrzesiekK126,项目名称:Wrocasion,代码行数:10,代码来源:DatabaseUtils.cs

示例9: GetOneElement

 public static string GetOneElement(string command)
 {
     string element = "";
     FbConnection con = new FbConnection(ConStr.ConnectionString);
     con.Open();
     FbTransaction transaction = con.BeginTransaction();
     FbCommand com = new FbCommand(command, con, transaction);
     com.ExecuteNonQuery();
     FbDataReader datareader;
     datareader = com.ExecuteReader();
     while (datareader.Read())
     {
         element = datareader[0].ToString();
     }
     con.Close();
     return element;
 }
开发者ID:GrzesiekK126,项目名称:Wrocasion,代码行数:17,代码来源:DatabaseUtils.cs

示例10: ExistsElement

 public static bool ExistsElement(string command)
 {
     string element = "";
     FbConnection con = new FbConnection(ConStr.ConnectionString);
     con.Open();
     FbTransaction transaction = con.BeginTransaction();
     FbCommand com = new FbCommand(command, con, transaction);
     com.ExecuteNonQuery();
     FbDataReader datareader;
     datareader = com.ExecuteReader();
     while (datareader.Read())
     {
         element = datareader[0].ToString();
     }
     con.Close();
     if (element != null && element != "")
         return true;
     return false;
 }
开发者ID:GrzesiekK126,项目名称:Wrocasion,代码行数:19,代码来源:DatabaseUtils.cs

示例11: Delete

        internal static void Delete(MovieInfo movieInfo)
        {
            string commandText = @"DELETE FROM MOVIE_DATA
                                    WHERE LOCATION = @location AND RAW_TITLE_PATH = @raw_title_path";

            using (FbConnection connection = new FbConnection (string.Format (CONNECTION_STRING_FORMAT_FIREBIRD, DB_FILENAME)))
            {
                connection.Open ();

                using (FbTransaction transaction = connection.BeginTransaction ())
                {
                    using (FbCommand cmd = new FbCommand (commandText, connection, transaction))
                    {
                        cmd.Parameters.Add (new FbParameter ("@location", movieInfo.DvdName));
                        cmd.Parameters.Add (new FbParameter ("@raw_title_path", movieInfo.RawTitlePath));

                        cmd.ExecuteNonQuery ();
                    }
                    transaction.Commit ();
                }
            }
        }
开发者ID:AZiegler71,项目名称:DVD-Sammlung,代码行数:22,代码来源:MoviePersistence.cs

示例12: IsInDatabase

 protected static bool IsInDatabase(Action<FbCommand> adjustCommand)
 {
     var result = false;
     using (var connection = new FbConnection(IntegrationTestOptions.Firebird.ConnectionString))
     {
         connection.Open();
         using (var tx = connection.BeginTransaction())
         {
             using (var cmd = connection.CreateCommand())
             {
                 cmd.Transaction = tx;
                 adjustCommand(cmd);
                 using (var reader = cmd.ExecuteReader())
                 {
                     result = reader.Read();
                 }
             }
             tx.Commit();
         }
         connection.Close();
     }
     return result;
 }
开发者ID:eloekset,项目名称:fluentmigrator,代码行数:23,代码来源:FbEndToEndFixture.cs

示例13: GetCompanies

        public List<Company> GetCompanies()
        {
            try
            {
                var myConnection = new FbConnection(GetConnectionString());
                myConnection.Open();

                var myTransaction = myConnection.BeginTransaction();
                var myCommand = new FbCommand
                {
                    Connection = myConnection,
                    Transaction = myTransaction,
                    CommandText = "SELECT * FROM COMPANIES ORDER BY CODE"
                };

                var myReader = myCommand.ExecuteReader();

                var companies = new List<Company>();
                while (myReader.Read())
                {
                    var company = new Company
                    {
                        Code = myReader["CODE"].ToString(),
                        Description = myReader["DESCRIPTION"].ToString()
                    };
                    companies.Add(company);
                }

                return companies;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
开发者ID:jjbaird87,项目名称:TMP_TAExporter,代码行数:36,代码来源:DataAccess.cs

示例14: LoadOwners

        public static void LoadOwners(Database databaseSettings)
        {
            _owners = new List<IOwnerData>();

            try
            {
                using (var connection = new FbConnection(GetConnectionString(databaseSettings)))
                {
                    connection.Open();

                    using (var command = new FbCommand("select * from firms order by id", connection,
                        connection.BeginTransaction(IsolationLevel.ReadCommitted)))
                    {
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                _owners.Add(new OwnerData
                                {
                                    ID = reader.GetString(0).Trim(),
                                    Name = reader.GetString(1).Trim(),
                                    Address = reader.GetString(2).Trim(),
                                    Inn = reader.GetString(3).Trim(),
                                    Kpp = reader.GetString(4).Trim(),
                                    Warrant = reader.GetString(5).Trim(),
                                    Section = reader.GetInt32(6)
                                });
                            }
                        }
                    }
                }
            }
            catch (FbException)
            {
            }
        }
开发者ID:Dennis-Petrov,项目名称:Cash,代码行数:36,代码来源:DatabaseHelper.cs

示例15: SqlSelect

        //private void _ConnectDB()
        //{
        //    if (!this.IsOpen())
        //        this._db.Open();
        //}
        //public void DisconnectDB()
        //{
        //    if (this.IsOpen())
        //        _db.Close();
        //}
        private List<Dictionary<string, string>> SqlSelect(string sqlQuery, string[] paramList)
        {
            List<Dictionary<string, string>> ret = new List<Dictionary<string, string>>();
            using (FbConnection db = new FbConnection(this._genLocalDBPathIfLocalDB(_connectionString)))
            {
                db.Open();
                using (FbTransaction trans = db.BeginTransaction())
                {
                    using (FbCommand cmd = new FbCommand(sqlQuery, db, trans))
                    {
                        for (int ii = 0; ii < Math.Floor(paramList.Count() / 2.0); ii++)
                        {
                            cmd.Parameters.AddWithValue(paramList[ii * 2], paramList[ii * 2 + 1]);
                        }

                        using (FbDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Dictionary<string, string> row = new Dictionary<string, string>();
                                for (int jj = 0; jj < reader.FieldCount; jj++)
                                {
                                    row.Add(reader.GetName(jj).ToLower(), reader.GetString(jj));
                                }
                                ret.Add(row);
                            }
                        }
                    }

                    trans.Commit();
                }
            }

            return ret;
        }
开发者ID:kindprojects,项目名称:workstation,代码行数:45,代码来源:AFbLink.cs


注:本文中的FirebirdSql.Data.FirebirdClient.FbConnection.BeginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。