當前位置: 首頁>>代碼示例>>C#>>正文


C# MySqlCommand.EndExecuteNonQuery方法代碼示例

本文整理匯總了C#中MySql.Data.MySqlClient.MySqlCommand.EndExecuteNonQuery方法的典型用法代碼示例。如果您正苦於以下問題:C# MySqlCommand.EndExecuteNonQuery方法的具體用法?C# MySqlCommand.EndExecuteNonQuery怎麽用?C# MySqlCommand.EndExecuteNonQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MySql.Data.MySqlClient.MySqlCommand的用法示例。


在下文中一共展示了MySqlCommand.EndExecuteNonQuery方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EjecutarQuery

 public static void EjecutarQuery(string querySQL, MySqlConnection connection)
 {
     try
         {
             MySqlCommand command = new MySqlCommand(querySQL, connection);
             connection.Open();
             IAsyncResult result = command.BeginExecuteNonQuery();
             while (!result.IsCompleted)
             {
                 Thread.Sleep(50);
             }
             command.EndExecuteNonQuery(result);
             connection.Close();
         }
         catch (SqlException ex)
         {
             throw ex;
         }
         catch (InvalidOperationException ex)
         {
             throw ex;
         }
         catch (MySqlException ex)
         {
             //Se captura en el caso de intentar guardar un cliente que ya esta en
             //la base de datos. Como no me interesa guardarlo, no hago nada.
             if (ex.Message.IndexOf("PRIMARY", StringComparison.Ordinal) <= 0)
                 throw ex;
         }
 }
開發者ID:jj-gallardo,項目名稱:CRat,代碼行數:30,代碼來源:ManejoDB.cs

示例2: ExecuteNonQuery

		public void ExecuteNonQuery()
		{
			if (version < new Version(5, 0)) return;

			execSQL("CREATE TABLE test (id int)");
			execSQL("CREATE PROCEDURE spTest() BEGIN SET @x=0; REPEAT INSERT INTO test VALUES(@x); " +
				"SET @[email protected]+1; UNTIL @x = 300 END REPEAT; END");

			try
			{
				MySqlCommand proc = new MySqlCommand("spTest", conn);
				proc.CommandType = CommandType.StoredProcedure;
				IAsyncResult iar = proc.BeginExecuteNonQuery();
				int count = 0;
				while (!iar.IsCompleted)
				{
					count++;
					System.Threading.Thread.Sleep(20);
				}
				proc.EndExecuteNonQuery(iar);
				Assert.IsTrue(count > 0);

				proc.CommandType = CommandType.Text;
				proc.CommandText = "SELECT COUNT(*) FROM test";
				object cnt = proc.ExecuteScalar();
				Assert.AreEqual(300, cnt);
			}
			catch (Exception ex)
			{
				Assert.Fail(ex.Message);
			}
			finally
			{
			}
		}
開發者ID:tdhieu,項目名稱:openvss,代碼行數:35,代碼來源:AsyncTests.cs

示例3: ExecuteQueryAsnyc

        public static void ExecuteQueryAsnyc(string MySqlCommand)
        {
            if (MySqlCommand != null)
            {
                Console.WriteLine(MySqlCommand);
                MySqlCommand Command = new MySqlCommand(MySqlCommand, connection);

                IAsyncResult result = Command.BeginExecuteNonQuery();
                while (!result.IsCompleted)
                {
                    System.Threading.Thread.Sleep(10);
                }
                Command.EndExecuteNonQuery(result);
            }
        }
開發者ID:CarlosX,項目名稱:DarkEmu,代碼行數:15,代碼來源:Database.cs

示例4: Handle

 public bool Handle()
 {
     List<Dictionary<string, object>> list = null;
     var nonQueryResult = 0;
     var lastInsertRowId = 0L;
     try
     {
         if (Connection == null) throw new Exception("Connection is null");
         //if (_result == null)
         //{
             _connection = Connection.Con;
             if (_connection.State == ConnectionState.Closed)
                 _connection.Open();
             _cmd = _connection.CreateCommand();
             _cmd.CommandText = Sql.SQL;
             Sql.AddParams(_cmd, Sql.Arguments, "@");
             _result = NonQuery ? _cmd.BeginExecuteNonQuery() : _cmd.BeginExecuteReader();
         //}
         _result.AsyncWaitHandle.WaitOne();
         //if (!_result.IsCompleted) return false;
         if (NonQuery)
             nonQueryResult = _cmd.EndExecuteNonQuery(_result);
         else
         {
             using (var reader = _cmd.EndExecuteReader(_result))
             {
                 list = new List<Dictionary<string, object>>();
                 while (reader.Read())
                 {
                     var dict = new Dictionary<string, object>();
                     for (var i = 0; i < reader.FieldCount; i++)
                     {
                         dict.Add(reader.GetName(i), reader.GetValue(i));
                     }
                     list.Add(dict);
                 }
             }
         }
         lastInsertRowId = _cmd.LastInsertedId;
         Cleanup();
     }
     catch (Exception ex)
     {
         var message = "MySql handle raised an exception";
         if (Connection?.Plugin != null) message += $" in '{Connection.Plugin.Name} v{Connection.Plugin.Version}' plugin";
         Interface.Oxide.LogException(message, ex);
         Cleanup();
     }
     Interface.Oxide.NextTick(() =>
     {
         Connection?.Plugin?.TrackStart();
         try
         {
             if (Connection != null) Connection.LastInsertRowId = lastInsertRowId;
             if (!NonQuery)
                 Callback(list);
             else
                 CallbackNonQuery?.Invoke(nonQueryResult);
         }
         catch (Exception ex)
         {
             var message = "MySql command callback raised an exception";
             if (Connection?.Plugin != null) message += $" in '{Connection.Plugin.Name} v{Connection.Plugin.Version}' plugin";
             Interface.Oxide.LogException(message, ex);
         }
         Connection?.Plugin?.TrackEnd();
     });
     return true;
 }
開發者ID:906507516,項目名稱:Oxide,代碼行數:69,代碼來源:MySql.cs


注:本文中的MySql.Data.MySqlClient.MySqlCommand.EndExecuteNonQuery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。