tags:

views:

53

answers:

3

i like to call the stored function in c#.i need articles and some examples for this

+1  A: 

http://forums.asp.net/p/988462/1278686.aspx

    MySqlCommand cmd = new MySqlCommand("DeleteMessage", new MySqlConnection(GetConnectionString()));
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add(new MySqlParameter("param1", MessageItem.Entry_ID));
    cmd.Connection.Open();
    int i = cmd.ExecuteNonQuery();
    cmd.Connection.Close();
Svisstack
WHR DO U GET RETURNING VALUE
ratty
@ratty: in `i` you have.
Svisstack
+2  A: 

It's almost identical to how you would call a SQL Server Stored Procedure:

using(MySqlConnection conn = new MySqlConnection(connString))
{
    MySqlCommand command = new MySqlCommand("spSomeProcedure;", conn);
    command.CommandType = System.Data.CommandType.StoredProcedure;

    // Add your parameters here if you need them
    command.Parameters.Add(new MySqlParameter("someParam", someParamValue));

    conn.Open();

    int result = (int)command.ExecuteScalar();
}
Justin Niessner
A: 

Stored routines

Stored functions and stored procedures are called in different ways.

Stored function is used as regular function in SQL statement. For example

SELECT id, title,  my_function(price) FROM table

Stored procedures are called using CALL statement.

CALL my_procedure(1,2,'title');

I don't know C#, so probably you can use MySqlCommand class to call stored procedures, but you can't use it to call stored functions.

Naktibalda