当前位置: 首页>>代码示例>>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;未经允许,请勿转载。