如何在C#中调用mySQL存储函数? [英] How to call a mySQL stored function in C#?

查看:222
本文介绍了如何在C#中调用mySQL存储函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用C#调用存储的函数.我需要一些文章和一些示例.

I'd like to call a stored function in C#. I need articles and some examples for this.

推荐答案

与调用SQL Server存储过程的方式几乎相同:

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();
}

这篇关于如何在C#中调用mySQL存储函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆