2
Reply

How to pass dynamically created into Stored procedure through SQL parameters in C#.NET?

Siva R

Siva R

12y
9.1k
0
Reply

    SqlCommand cmd = new SqlCommand("Sp_Bank");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@ActionId",SqlDbType.Int);
            cmd.Parameters.Add("@Aref", SqlDbType.Decimal);
            cmd.Parameters.Add("@Aref", SqlDbType.Decimal);

            ***********All The Parameter****************
            int result = cmd.ExecuteNonQuery();

    ---Create Store procedure Like
    ==============================================
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go

    -- =============================================
    -- Author: piyush sardhara
    -- Create date:         <11-04-11>
    -- Description:
    -- =============================================
    ALTER PROCEDURE [dbo].[Sp_Bank]
    (
    @ActionId int=0,
    @Aref numeric(18, 0)=0,
    @BName nvarchar(50)='',
    @AcName nvarchar(50)='',
    @acno nvarchar(50)='',
    @ifsc nvarchar(50)='',
    @branch nvarchar(50)='',
    @blogo nvarchar(MAX)=''

    )
    AS
    BEGIN
       if @ActionId=0
    BEGIN
    insert into Bank(BName,AcName,acno,ifsc,branch,blogo)
     values(@BName,@AcName,@acno,@ifsc,@branch,@blogo)
    END
    END

    ===============================================
    --pass value like this in Cs Page
    ===============================================

                    string[] pAdd = new string[6];
                    pAdd[0] = TxtBname.Text.Trim();
                    pAdd[1] = TxtAName.Text.Trim();
                    pAdd[2] = TxtAcNo.Text.Trim();
                    pAdd[3] = TxtIFSC.Text.Trim();
                    pAdd[4] = TxtBranch.Text.Trim();
                    pAdd[5] = LblPath.Text.Trim();


    ================================================
    if you like my ans is good rate to me.