How to execute a stored procedure within C# program

前端 未结 13 1656
别跟我提以往
别跟我提以往 2020-11-22 00:10

I want to execute this stored procedure from a C# program.

I have written the following stored procedure in a SqlServer query window and saved it as stored1:

<
13条回答
  •  再見小時候
    2020-11-22 00:22

    Using Dapper. so i added this i hope anyone help.

    public void Insert(ProductName obj)
            {
                SqlConnection connection = new SqlConnection(Connection.GetConnectionString());
                connection.Open();
                connection.Execute("ProductName_sp", new
                { @Name = obj.Name, @Code = obj.Code, @CategoryId = obj.CategoryId, @CompanyId = obj.CompanyId, @ReorderLebel = obj.ReorderLebel, @logo = obj.logo,@Status=obj.Status, @ProductPrice = obj.ProductPrice,
                    @SellingPrice = obj.SellingPrice, @VatPercent = obj.VatPercent, @Description=obj.Description, @ColourId = obj.ColourId, @SizeId = obj.SizeId,
                    @BrandId = obj.BrandId, @DisCountPercent = obj.DisCountPercent, @CreateById =obj.CreateById, @StatementType = "Create" }, commandType: CommandType.StoredProcedure);
                connection.Close();
            }
    

提交回复
热议问题