Oracle 5.0 Reference Manual page 1878

Table of Contents

Advertisement

object, and then processed, for example the results might be displayed. The
MySqlDataReader
following code demonstrates how this could be done.
using System;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
public class Tutorial2
{
public static void Main()
{
string connStr = "server=localhost;user=root;database=world;port=3306;password=******;";
MySqlConnection conn = new MySqlConnection(connStr);
try
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();
string sql = "SELECT Name, HeadOfState FROM Country WHERE Continent='Oceania'";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine(rdr[0]+" -- "+rdr[1]);
}
rdr.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
conn.Close();
Console.WriteLine("Done.");
}
}
When a connection has been created and opened, the code then creates a
object. Note that the SQL query to be executed is passed to the
method is then used to generate a
ExecuteReader
contains the results generated by the SQL executed on the command object. Once the results have
been obtained in a
MySqlReader
is printed out by a
while
method on it.
In the next example, you will see how to use the
The procedure for performing an
to create an object to store results. This is because
updating and deleting data. The following example illustrates a simple update to the
using System;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
public class Tutorial3
{
public static void Main()
{
string connStr = "server=localhost;user=root;database=world;port=3306;password=******;";
MySqlConnection conn = new MySqlConnection(connStr);
try
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();
Connector/Net Tutorials
object, the results can be processed. In this case, the information
loop. Finally, the
MySqlReader
ExecuteNonQuery
1858
MySqlCommand
object. The
MySqlReader
object is disposed of by running its
method.
ExecuteNonQuery
method call is simpler, as there is no need
ExecuteNonQuery
MySqlCommand
constructor. The
MySqlReader
Close
is only used for inserting,
table:
Country
object

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents