如何获得两个价值 [英] how to get both values

查看:75
本文介绍了如何获得两个价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var parametertaxitem = new SqlParameter("@taxitemid", SqlDbType.Int, (50));
parametertaxitem.Value = valu121;
parametertaxitem.Value = value22;
myCommand.Parameters.Add(parametertaxitem);


在这里,我得到了value22的最后一个值,我需要同时获得value121和value22的两个值.


here i get last value of value22, i need both values of value121, and value22 how to get it.

推荐答案

一种解决方法是必须运行您的proc两次,一次的值为"valu121",而在下一回合中,您将运行同一个proc的值为"value22".

例如:

第一次:
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:
           // 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:

           // 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!


您好,
根据您的编码,您将无法获得参数值,即"value21",因为"value22"正在替换参数的先前值.您可以使用单个参数来获取和设置机器人参数.使用这个:
如果可以在SP中使用两个参数:
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:
//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:

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:

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



祝一切顺利.
--Amit



All the best.
--Amit


这篇关于如何获得两个价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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