如何使用表变量创建过程作为参数,并从ADO.net调用它 [英] How to create Procedure with table variable as paramenter and call it from ADO.net

查看:69
本文介绍了如何使用表变量创建过程作为参数,并从ADO.net调用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从c#中调用接受表变量作为参数的过程。



谢谢,

How can we call a procedure that accepts table variable as parameter from c#.

Thanks,

推荐答案

下面给出了一个使用表类型参数调用存储过程的示例 -



Given below is an example of calling Stored Procedure with Table type Parameter -

public static void saveProductPricing(DataTable ProductPricing)
{
    try
    {
        using (SqlConnection sqlConn = new SqlConnection(Common.ConnectionString))
        {
            sqlConn.Open();
            SqlCommand cmdExecute = new SqlCommand();

            cmdExecute.CommandText = "spSaveProductPricing";
            cmdExecute.CommandType = CommandType.StoredProcedure;
            cmdExecute.CommandTimeout = 0;
            cmdExecute.Connection = sqlConn;

            cmdExecute.Parameters.AddWithValue("@ProductPricing", ProductPricing);

            //Also works without below code
            cmdExecute.Parameters["@ProductPricing"].SqlDbType = SqlDbType.Structured;

            cmdExecute.ExecuteNonQuery();
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}


这篇关于如何使用表变量创建过程作为参数,并从ADO.net调用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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