Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can we call a procedure that accepts table variable as parameter from c#.

Thanks,
Posted

1 solution

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

C#
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;
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900