hello,
Anyone have any idea how to create a stored procedure with c# or vb.net?
My code is as follows, but it shows a syntax error and from workbench it runs without errors.
*****************************************************
String query = "USE `databasename`;";
query += " DROP procedure IF EXISTS `sp_create`;";
query += " DELIMITER $$";
query += " CREATE DEFINER=`user`@`%` PROCEDURE `sp_create` (";
query += " in vId int(11), in vfName varchar(150)";
query += " )";
query += " BEGIN";
query += " INSERT INTO Contacts (Id, fName)";
query += " VALUES (vId, vfName);";
query += " SELECT LAST_INSERT_ID() AS IdRegistro;";
query += " END$$";
ExecuteCommand(query);
private static void ExecuteCommand(string queryString,
string connectionString)
{
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
command.Connection.Open();
command.ExecuteNonQuery();
}
}
**********************************
thanks,
Anyone have any idea how to create a stored procedure with c# or vb.net?
My code is as follows, but it shows a syntax error and from workbench it runs without errors.
*****************************************************
String query = "USE `databasename`;";
query += " DROP procedure IF EXISTS `sp_create`;";
query += " DELIMITER $$";
query += " CREATE DEFINER=`user`@`%` PROCEDURE `sp_create` (";
query += " in vId int(11), in vfName varchar(150)";
query += " )";
query += " BEGIN";
query += " INSERT INTO Contacts (Id, fName)";
query += " VALUES (vId, vfName);";
query += " SELECT LAST_INSERT_ID() AS IdRegistro;";
query += " END$$";
ExecuteCommand(query);
private static void ExecuteCommand(string queryString,
string connectionString)
{
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
command.Connection.Open();
command.ExecuteNonQuery();
}
}
**********************************
thanks,