Oracle 5.0 Reference Manual page 1913

Table of Contents

Advertisement

CREATE DATABASE TestDB;
USE TestDB;
CREATE TABLE TestTable (id INT NOT NULL PRIMARY KEY
AUTO_INCREMENT, name VARCHAR(100));
The main method of the
MySqlScript
(sequence of statements) assigned to the Query property of the MySqlScript object to be executed.
Note the Query property can be set through the
property.
returns the number of statements executed.
Execute
The
object will execute the specified script on the connection set using the Connection
MySqlScript
property. Again, this property can be set directly or through the
following code snippets illustrate this:
string sql = "SELECT * FROM TestTable";
...
MySqlScript script = new MySqlScript(conn, sql);
...
MySqlScript script = new MySqlScript();
script.Query = sql;
script.Connection = conn;
...
script.Execute();
The MySqlScript class has several events associated with it. There are:
1. Error - generated if an error occurs.
2. ScriptCompleted - generated when the script successfully completes execution.
3. StatementExecuted - generated after each statement is executed.
It is possible to assign event handlers to each of these events. These user-provided routines are called
back when the connected event occurs. The following code shows how the event handlers are set up.
script.Error += new MySqlScriptErrorEventHandler(script_Error);
script.ScriptCompleted += new EventHandler(script_ScriptCompleted);
script.StatementExecuted += new MySqlStatementExecutedEventHandler(script_StatementExecuted);
In VisualStudio, you can save typing by using tab completion to fill out stub routines. Start by typing, for
example, "script.Error +=". Then press TAB, and then press TAB again. The assignment is completed,
and a stub event handler created. A complete working example is shown below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace MySqlScriptTest
{
class Program
{
static void Main(string[] args)
{
string connStr = "server=localhost;user=root;database=TestDB;port=3306;password=******;";
MySqlConnection conn = new MySqlConnection(connStr);
try
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();
string sql = "INSERT INTO TestTable(name) VALUES ('Superman');" +
Connector/Net Tutorials
class is the
Execute
MySqlScript
"INSERT INTO TestTable(name) VALUES ('Batman');" +
"INSERT INTO TestTable(name) VALUES ('Wolverine');" +
"INSERT INTO TestTable(name) VALUES ('Storm');";
1893
method. This method causes the script
constructor or using the Query
constructor. The
MySqlScript

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents