Re: Creating Functions and Procedures from the program
Posted by: Fernando Gonzalez
Date: November 05, 2012 12:09PM

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.

Options: ReplyQuote




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.