本文整理汇总了C#中MySql.Data.MySqlClient.MySqlCommand.EndExecuteReader方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlCommand.EndExecuteReader方法的具体用法?C# MySqlCommand.EndExecuteReader怎么用?C# MySqlCommand.EndExecuteReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlCommand
的用法示例。
在下文中一共展示了MySqlCommand.EndExecuteReader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteReader
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);
}
}
示例2: ExecuteReaderAsyncTest
public void ExecuteReaderAsyncTest() {
using(var conn = new MySqlConnection(DefaultConnectionString))
using(var cmd = new MySqlCommand(SQL_CUSTOMER_SELECT, conn)) {
conn.Open();
//! MySqlCommandAsync 를 참조하세요
//
var ar = cmd.BeginExecuteReader();
Thread.Sleep(1);
using(var reader = cmd.EndExecuteReader(ar)) {
var customers = reader.Map<Customer>(() => new Customer(), new TrimNameMapper());
customers.Count.Should().Be.GreaterThan(0);
customers.All(customer => customer.CompanyName.IsNotWhiteSpace()).Should().Be.True();
}
}
}
示例3: ObtenerTodos
public ArrayList ObtenerTodos()
{
this.InciarConeccion ();
MySqlCommand comando = new MySqlCommand(QueryDeConneccion(),this.myConeccion);
MySqlDataReader Lector = comando.EndExecuteReader ();
ArrayList ListaArreglos = new ArrayList ();
datos Datos = new datos ();
while (Lector.Read())
{
Datos.idVideojuego = Lector["idVideojuego"].ToString;
Datos.nombre = Lector["nombre"].ToString;
Datos.Anio = Lector ["ano"].ToString;
Datos.FabricanteNombre = Lector["Fabricante_nombre"].ToString;
ListaArreglos.Add (Datos);
}
return ListaArreglos;
}
示例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;
}
示例5: ThrowingExceptions
public void ThrowingExceptions()
{
MySqlCommand cmd = new MySqlCommand("SELECT xxx", conn);
IAsyncResult r = cmd.BeginExecuteReader();
try
{
MySqlDataReader reader = cmd.EndExecuteReader(r);
if (reader != null)
reader.Close();
Assert.Fail("EndExecuteReader should have thrown an exception");
}
catch (MySqlException)
{
}
}
示例6: RunMySqlCommand
private static ArrayList RunMySqlCommand(
string commandText,
string connectionString,
int no_of_fields)
{
ArrayList rows = new ArrayList();
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
try
{
//Console.WriteLine("commandtext: " + commandText);
MySqlCommand command = new MySqlCommand(commandText, connection);
connection.Open();
IAsyncResult result = command.BeginExecuteReader();
int count = 0;
//DateTime start_time = DateTime.Now;
while (!result.IsCompleted)
{
count += 1;
//Console.WriteLine("Waiting ({0})", count);
System.Threading.Thread.Sleep(100);
//TimeSpan diff = DateTime.Now.Subtract(start_time);
//if (diff.TotalSeconds > 30) break;
}
MySqlDataReader query_result = command.EndExecuteReader(result);
while (query_result.Read())
{
ArrayList row = new ArrayList();
for (int i = 0; i < no_of_fields; i++)
{
row.Add(query_result.GetValue(i));
}
rows.Add(row);
}
connection.Close();
}
catch (MySqlException ex)
{
Console.WriteLine("Error ({0}): {1}", ex.Number, ex.Message);
connection.Close();
}
catch (InvalidOperationException ex)
{
Console.WriteLine("Error: {0}", ex.Message);
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex.Message);
connection.Close();
}
}
return(rows);
}
示例7: SelectData
IEnumerator SelectData()
{
// SQL�R�}���h��쐬
string conCmd =
"server=" + SERVER + ";" +
"database=" + DATABASE + ";" +
"userid=" + USERID + ";" +
// "port=" + PORT + ";" +
"password=" + PASSWORD;
// SQL�R�l�N�V������쐬
MySqlConnection con = null;
try
{
// SQL�ڑ�����{����
con = new MySqlConnection(conCmd);
con.Open();
}
finally { }
/* TODO�@�悭������Ǔ����Ȃ�����p�b�`���O��finally����
catch (MySqlException ex)
{
Debug.Log(ex.ToString());
}
*/
// �f�[�^��lj�����INSERT���́A�ʏ��MySqlCommand�N���X��g���܂��B
// �R�}���h��쐬
string selCmd = "SELECT * FROM TABLENAME LIMIT 0, 1200;";
MySqlCommand cmd = new MySqlCommand(selCmd, con);
// ��������J�n
IAsyncResult iAsync = cmd.BeginExecuteReader();
// ���ɂ��S�f�[�^�擾�����܂ő҂����킹��
while (!iAsync.IsCompleted)
{
yield return 0;
}
// �ꉞ�F
// ��L��while�Ŋ�����҂ȊO�ɁABegin�ɂ����J�n���ɃI�[�o�[���[�h��
// cmd.BeginExecuteReader(new AsyncCallback(AsyncCallbackMethod), cmd);
// �Ƃ��Ĕ�������������R�[���o�b�N���\�b�h��ĂсA���̒��Ŋ���EndExcuteReader
// ��ĂԎ���ł���B
// �������́A���������I������ۂɃR�[���o�b�N����郁�\�b�h�B
// ��������IAsyncResult.AsyncState�I�u�W�F�N�g�Ƃ��Ď擾�ł���I�u�W�F�N�g�B
// �ŁA�R�[���o�b�N���\�b�h��void AsyncCallbackMethod(IAsyncResult result)
// result�ɂ͑������Ŏw�肵��cmd������B
// ���������������
MySqlDataReader rdr = cmd.EndExecuteReader(iAsync);
// �擾�����f�[�^����ID�Ă݂�
while (rdr.Read())
{
if (!rdr.IsDBNull(rdr.GetOrdinal("ID")))
{
Debug.Log ( "ID : " + rdr.GetString ("ID") );
}
}
// �S���\�[�X��N���[�Y����щ������
rdr.Close();
rdr.Dispose();
con.Close();
con.Dispose();
}