GVKun编程网logo

在SQL Server的一个参数中传递多个值(向sql语句中传递参数)

13

如果您想了解在SQLServer的一个参数中传递多个值的相关知识,那么本文是一篇不可错过的文章,我们将对向sql语句中传递参数进行全面详尽的解释,并且为您提供关于AJAX+Webservice传递多个

如果您想了解在SQL Server的一个参数中传递多个值的相关知识,那么本文是一篇不可错过的文章,我们将对向sql语句中传递参数进行全面详尽的解释,并且为您提供关于AJAX+Webservice传递多个参数、asp.net – 在MVC 3中的url中传递多个参数、c# – 如何在Task中传递多个参数、C#向线程中传递多个参数的解决方法(两种)的有价值的信息。

本文目录一览:

在SQL Server的一个参数中传递多个值(向sql语句中传递参数)

在SQL Server的一个参数中传递多个值(向sql语句中传递参数)

Create procedure [dbo].[sp_Sample]
    @param1 varchar(100)
as
   DECLARE @Sql VARCHAR(MAX)
   SET @param1 = REPLACE(@param1,',''',''')
   SET @Sql = 'select * from tblSample where col1 IN (''' + @param1 + ''')'
Go

DECLARE @return_value int

EXEC @return_value = [dbo].[sp_Sample]
     @Escalation = N'SIM4'

SELECT  'Return Value' = @return_value
GO

当我执行此过程时,什么也不显示

如果有什么问题建议我

谢谢

AJAX+Webservice传递多个参数

AJAX+Webservice传递多个参数

html页面

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="js/Jquery1.7.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $(''#Button1'').click(function () {
                $.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/GetList",
                    data: "{}",
                    success: function (result) {
                        var str = '''';
                        for (var i = 0; i < result.d.length; i++) {
                            str += result.d[i];
                        }
                        $(''#mydiv'').text(str);
                    }
                })
            })
        })
    </script>

</head>
<body>
<div id="mydiv"></div>
    <input id="Button1" type="button" value="button" />
</body>
</html>

Webservice页面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebAjax
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolBoxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
       
        public List<string> GetList()
        {
            List<string> list = new List<string>();
            list.Add("张三");
            list.Add("20");
            list.Add("河北");
            return list;

        }     } }

asp.net – 在MVC 3中的url中传递多个参数

asp.net – 在MVC 3中的url中传递多个参数

我在控制器中有一个名为“Registration”的动作方法

public ActionResult Facility(int id = 0,int contractId = 0)

当我从url调用这个方法时

/Registration/Facility/0?contractId=0

它工作正常.现在,当我尝试在另一种方法中构建上面的url时

return RedirectToAction("Facility/0?contractId="+ model.ContractId);

它不起作用,浏览器中的网址构造不好就像它

/Registration/Facility/0%3fcontractId%3d0

任何人都可以告诉我,我在这里做错了什么?

解决方法

试试这个:

return RedirectToAction("Facility",new { id = 0,contractId = model.ContractId});

见this answer

c# – 如何在Task中传递多个参数

c# – 如何在Task中传递多个参数

我有一个函数Ge​​tPiVotedDataTable(data,“date”,“id”,“flag”)以PiVoted格式返回数据.我想使用Task调用这个方法,但是如何在Task中传递多个参数.

解决方法

您可以使用lambda表达式或Func传递参数:)
public Form1()
{
    InitializeComponent();

    Task task = new Task(() => this.GetPiVotedDataTable("x",DateTime.UtcNow,1,"test"));
    task.Start();
}

public void GetPiVotedDataTable(string data,DateTime date,int id,string flag)
{
    // Do stuff
}

C#向线程中传递多个参数的解决方法(两种)

C#向线程中传递多个参数的解决方法(两种)

问题:

对于多线程编程,很多时候往往需要向线程中传递多个参数,而C#中的线程只接收1个object类型的参数(如下):

Thread t = new Thread(new ParameterizedThreadStart(newthread));
t.start(参数);
void newthread(object)
{
.............
}

而现在需要往线程中传递多个参数,比如method方法想用单独的线程来跑

void method(int begin,int end)
{
..................
}

解决办法1:新建一个跑方法的类

class myclass
{
private int begin;
public int begin
{
set{this.begin=value;}
}
private int end;
public int end
{
set{this.end=value;}
}
public run()
{
method(begin,end);
}
private method(int begin,int end)
{
...............
}
}

然后新建一个该类实例,赋值之后就可以跑了,代码如下;

myclass c = new myclass();
c.begin=100;
c.end=10000;
Thread t = new Thread(new Threadstart(c.run))
t.start();

2、解决方法2:将数组或集合实例作为参数传入

目前正在做一个多线程的软件,用到了这部分,感觉每次都要新建类,比较麻烦,查了网上主流都是解决方法1中的方法,后来自己琢磨出另一个方法,就是尽管新的线程只能传1个参数进去,但是我们可以传一个集合或者数组类的参数进去,这样就可以解决一次向新线程中传递多个参数的问题了。

同样,对于上面的method的方法,需要传递2个int类型的整数,首先添加一个method方法的重载

void method(object o)
{
//此处对传进来的参数进行处理
int[] p = (int[])o;
//调用原来的method方法
method(p[0],p[1]);
}

再将要传递的参数用数组或集合方式储存起来

int para[]=new int[2]{100,10000};

最后新建线程进行调用

THread t = new Thread(new ParameterizedThreadStart(method))
t.start(para);

这样就可以达到将2个参数传递入线程的目的了。

传递的参数类型也可以用List<>或其他集合,传递进去的这些参数的类型都是相同的,对于不同的类型,可以考虑采用List<object>或者object[] 的方式传进去,在重载的方法中再对参数进行处理即可。

以上所述是小编给大家介绍的C#向线程中传递多个参数的解决方法(两种) ,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

今天关于在SQL Server的一个参数中传递多个值向sql语句中传递参数的分享就到这里,希望大家有所收获,若想了解更多关于AJAX+Webservice传递多个参数、asp.net – 在MVC 3中的url中传递多个参数、c# – 如何在Task中传递多个参数、C#向线程中传递多个参数的解决方法(两种)等相关知识,可以在本站进行查询。

本文标签: