Oracle 5.0 Reference Manual page 1928

Table of Contents

Advertisement

Next
Catch ex As MySqlException
MessageBox.Show("Error " & ex.Number & " has occurred: " & ex.Message, "Error", MessageBoxButtons.OK, M
End Try
C# Example
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
conn = new MySql.Data.MySqlClient.MySqlConnection();
cmd = new MySql.Data.MySqlClient.MySqlCommand();
conn.ConnectionString = strConnection;
try
{
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO myTable VALUES(NULL, @number, @text)";
cmd.Prepare();
cmd.Parameters.AddWithValue("@number", 1);
cmd.Parameters.AddWithValue("@text", "One");
for (int i=1; i <= 1000; i++)
{
cmd.Parameters["@number"].Value = i;
cmd.Parameters["@text"].Value = "A string value";
cmd.ExecuteNonQuery();
}
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
20.2.5.9. Accessing Stored Procedures with Connector/Net
MySQL server version 5 and up supports stored procedures with the SQL 2003 stored procedure
syntax.
A stored procedure is a set of SQL statements that is stored in the server. Clients make a single call to
the stored procedure, passing parameters that can influence the procedure logic and query conditions,
rather than issuing individual hardcoded SQL statements.
Stored procedures can be particularly useful in situations such as the following:
• Stored procedures can act as an API or abstraction layer, allowing multiple client applications to
perform the same database operations. The applications can be written in different languages and
run on different platforms. The applications do not need to hardcode table and column names,
complicated queries, and so on. When you extend and optimize the queries in a stored procedure, all
the applications that call the procedure automatically receive the benefits.
• When security is paramount, stored procedures keep applications from directly manipulating
tables, or even knowing details such as table and column names. Banks, for example, use stored
procedures for all common operations. This provides a consistent and secure environment, and
procedures can ensure that each operation is properly logged. In such a setup, applications and
users would not get any access to the database tables directly, but can only execute specific stored
procedures.
Connector/Net supports the calling of stored procedures through the
be passed in and out of a MySQL stored procedure through use of the
collection.
Connector/Net Programming
1908
object. Data can
MySqlCommand
MySqlCommand.Parameters

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents