Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
C#
var parametertaxitem = new SqlParameter("@taxitemid", SqlDbType.Int, (50));
parametertaxitem.Value = valu121;
parametertaxitem.Value = value22;
myCommand.Parameters.Add(parametertaxitem);

here i get last value of value22, i need both values of value121, and value22 how to get it.
Posted
Updated 30-Jul-12 18:20pm
v2
Comments
Kenneth Haugland 30-Jul-12 8:14am    
What do you mean value21 + value22 ?
pradiprenushe 30-Jul-12 8:19am    
Why you want single parameter?
2011999 30-Jul-12 8:20am    
add the table in value21,value22 row wise
2011999 30-Jul-12 8:21am    
in my database table single parameter assign multiple values
_Amy 30-Jul-12 8:34am    
Check my updated answer.!

One way to work around is that you have to run your proc two times, one time with the value of "valu121" and in the next turn you will run the same proc with value "value22".

For example:

first time:
C#
           // assign paramater with value= valu121
           var parametertaxitem = new SqlParameter("@taxitemid", SqlDbType.Int, (50));
           parametertaxitem.Value = valu121;
           myCommand.Parameters.Add(parametertaxitem);

// run your proc and it will insert an entry in table with "tax_item_id" column = "valu121"


then in the second attempt run the same proc like:

C#
           // assign paramater with value= value22
           var parametertaxitem = new SqlParameter("@taxitemid", SqlDbType.Int, (50));
           parametertaxitem.Value = value22;
           myCommand.Parameters.Add(parametertaxitem);

// run your proc and it will insert an entry in table with "tax_item_id" column = "value22"


Hope it helps!
 
Share this answer
 
Comments
_Amy 31-Jul-12 0:28am    
Not a good practice to run same procedure to times.
Shahan Ayyub 31-Jul-12 1:56am    
It is not good if there are series of elements, but in case of two it can be used.
_Amy 31-Jul-12 2:23am    
Voted Up here also. +5!. :)
Hi,
According to your coding, you won't be able to get parameter value i.e. "value21", because "value22" is replacing the previous value of your parameter. You can use individual parameters to get and set bot parameters. Use this:
If you can use two parameters in your SP:
C#
//1st Parameter
var parametertaxitem1 = new SqlParameter("@taxitemid1", SqlDbType.Int, (50));
parametertaxitem1.Value = valu121;
myCommand.Parameters.Add(parametertaxitem1);

//2nd parameter
var parametertaxitem2 = new SqlParameter("@taxitemid2", SqlDbType.Int, (50));
parametertaxitem2.Value = value22;
myCommand.Parameters.Add(parametertaxitem2);

If you are using only one parameter:
Concatenate the strings using special character and split it in your stored procedure. Like:
C#
var parametertaxitem = new SqlParameter("@taxitemid", SqlDbType.Int, (50));
parametertaxitem.Value = valu121.ToString()+"±"+value22.ToString();
myCommand.Parameters.Add(parametertaxitem);

Now you are receiving both the values. Just split it in your stored procedure and use it. Like:
SQL
SET QUOTED_IDENTIFIER ON 
GO 
ALTER PROCEDURE [dbo].[ETIPSAVE_SP] 
    @taxitemid int , 
    @empid int, 
    @amount int , 
    @Etid int OUTPUT 
AS 
BEGIN
    DECLARE @taxitemid1 VARCHAR(10)
    DECLARE @taxitemid2 VARCHAR(10)
    SET  @taxitemid1 = substring(@val, 0,  charindex('±', @taxitemid ))--Finding first ID
    SET  @taxitemid2 = substring(@val, charindex('±', @taxitemid)+1, LEN(@taxitemid)) -- Findig second ID
    --Inserting the values
    INSERT INTO Employee_Tax_item_Payroll ( tax_item_id, emp_id, amount ) VALUES ( @taxitemid1, @empid , @amount ), ( @taxitemid2, @empid , @amount )
    SELECT @etid = @@Identity
END


All the best.
--Amit
 
Share this answer
 
v5
Comments
2011999 30-Jul-12 8:37am    
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ETIPSAVE_SP]
(
@taxitemid int ,
@empid int,
@amount int ,


@Etid int OUTPUT
)
AS

INSERT INTO Employee_Tax_item_Payroll
(
tax_item_id,
emp_id,
amount
)

VALUES
(
@taxitemid,
@empid ,
@amount


)

SELECT
@etid = @@Identity
2011999 30-Jul-12 8:42am    
where to change it
_Amy 30-Jul-12 8:51am    
Use my updated answer's procedure..

Accept if it is working.. :)
_Amy 30-Jul-12 9:02am    
What is this? Down-voted? Any problem with the coding?
2011999 31-Jul-12 0:14am    
Msg 102, Level 15, State 1, Procedure ETIPSAVE_SP, Line 20
Incorrect syntax near '@@Identity'.

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