MySql.Data.MySqlClient.MySqlCommand.EndExecuteReader C# (CSharp) Method

EndExecuteReader() public method

Finishes asynchronous execution of a SQL statement, returning the requested MySqlDataReader.
public EndExecuteReader ( IAsyncResult result ) : MySqlDataReader
result IAsyncResult The returned by the call to /// .
return MySqlDataReader
		public MySqlDataReader EndExecuteReader(IAsyncResult result)
		{
			result.AsyncWaitHandle.WaitOne();
            AsyncDelegate c = caller;
            caller = null;
            if (thrownException != null)
                throw thrownException;
            return (MySqlDataReader)c.EndInvoke(result);
		}

Usage Example

コード例 #1
0
		public void ExecuteReader()
		{
            if (Version < new Version(5, 0)) return;

			execSQL("CREATE TABLE test (id int)");
			execSQL("CREATE PROCEDURE spTest() BEGIN INSERT INTO test VALUES(1); " +
				"SELECT SLEEP(2); SELECT 'done'; END");

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

			using (MySqlDataReader reader = proc.EndExecuteReader(iar))
            {
				Assert.IsNotNull(reader);
				Assert.IsTrue(count > 0, "count > 0");
				Assert.IsTrue(reader.Read(), "can read");
				Assert.IsTrue(reader.NextResult());
				Assert.IsTrue(reader.Read());
				Assert.AreEqual("done", reader.GetString(0));
				reader.Close();

				proc.CommandType = CommandType.Text;
				proc.CommandText = "SELECT COUNT(*) FROM test";
				object cnt = proc.ExecuteScalar();
				Assert.AreEqual(1, cnt);
			}
		}
All Usage Examples Of MySql.Data.MySqlClient.MySqlCommand::EndExecuteReader