Re: Creating Functions and Procedures from the program
Hi,
You cannot create stored routines inside another stored routine.
You cannot create them in C# using MySqlCommand neither, but can use MySqlScript, a sample follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace MyWorkbench
{
class Program
{
static void Main(string[] args)
{
MySqlConnection con = new MySqlConnection("<your connection string here");
con.Open();
MySqlScript scr = new MySqlScript( con );
scr.Delimiter = "//";
scr.Query = @"drop procedure if exists spCreator //
create procedure spCreator()
begin
set @s = 'select 1;';
prepare stmt1 from @s;
execute stmt1;
deallocate prepare stmt1;
end //";
scr.Execute();
con.Close();
}
}
}
In this sample, the stored procedure is using prepared statements, but it can be just about anything allowed in MySql server itself.
Thanks.
Subject
Written By
Posted
November 05, 2012 06:21AM
Re: Creating Functions and Procedures from the program
November 05, 2012 12:09PM
November 05, 2012 12:16PM
November 05, 2012 02:43PM
November 05, 2012 03:41PM
November 05, 2012 03:46PM
November 07, 2012 03:18AM
November 07, 2012 10:12AM
November 27, 2012 06:47AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.