Ver Mensaje Individual
  #9 (permalink)  
Antiguo 04/01/2012, 16:33
sephiroth007234
 
Fecha de Ingreso: septiembre-2010
Mensajes: 5
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: MySQL WorkBench sintaxis Stored Procedures

Hola...

Lo prometido es deuda... Aquí dejo el procedimiento (resumido)

-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_crear_usuario`(In nombre varchar(15), In apellidos varchar(15), In nick varchar(15), In pass varchar(50))
BEGIN
INSERT INTO usuario (usuario.nombre, usuario.apellidos, usuario.nick, usuario.pass)VALUES (nombre, apellidos, nick, pass);
SELECT MAX(usuario.idusuario) FROM usuario;
END

y se utiliza desde la aplicación:

MySqlCommand command = new MySqlCommand("sp_crear_usuario", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@nombre", usuario.Nombre);
command.Parameters.AddWithValue("@apellidos", usuario.Apellidos);
command.Parameters.AddWithValue("@nick", usuario.Nick);
string password = EncriptaPassword(string.Concat(usuario.Nick, usuario.Password));
command.Parameters.AddWithValue("@pass", password);
conn.Open();
usuario.Id_usuario = Convert.ToInt32(command.ExecuteScalar());
usuario.Password = password;
return usuario;

Y todo va de 10, uso el MySQL conector 6.3.6... Saludos