相关疑难解决方法(0)

参数化SQL IN子句

如何参数化包含IN具有可变数量参数的子句的查询,比如这个?

SELECT * FROM Tags 
WHERE Name IN ('ruby','rails','scruffy','rubyonrails')
ORDER BY Count DESC
Run Code Online (Sandbox Code Playgroud)

在此查询中,参数的数量可以是1到5之间的任何值.

我不希望为此(或XML)使用专用存储过程,但如果有一些特定于SQL Server 2008的优雅方式,我对此持开放态度.

sql sql-server parameters

1020
推荐指数
29
解决办法
33万
查看次数

将一组参数传递给存储过程

我需要将一个"id"的数组传递给一个存储过程,删除表中的所有行,除了与数组中的id匹配的行.

我怎么能以最简单的方式做到这一点?

sql stored-procedures sql-server-2005

74
推荐指数
4
解决办法
12万
查看次数

表值可选参数

是否可以使用表值参数作为可选参数创建过程.

我尝试了以下代码:

CREATE PROCEDURE SP
@Table testteype = null READONLY
AS 
....
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

Operand type clash: void type is incompatible with test type 
Run Code Online (Sandbox Code Playgroud)

ps:我使用C#.Net的sql server

c# sql-server

22
推荐指数
2
解决办法
8636
查看次数

将数组传递给SQL Server存储过程

如何使用C#将数组变量传递给SQL Server存储过程并将数组值插入整行?

提前致谢.

SQL Server表:

ID    | Product | Description
-------------------------------
8A3H  | Soda    | 600ml bottle
Run Code Online (Sandbox Code Playgroud)

C#数组:

string[] info = new string[] {"7J9P", "Soda", "2000ml bottle"};
Run Code Online (Sandbox Code Playgroud)

SQL Server存储过程:

ALTER PROC INSERT
    (@INFO_ARRAY ARRAY)
AS
BEGIN
    INSERT INTO Products VALUES (@INFO_ARRAY)
END
Run Code Online (Sandbox Code Playgroud)

c# t-sql sql-server arrays ado.net

11
推荐指数
1
解决办法
3万
查看次数

将Dictionary <string,int>传递给存储过程T-SQL

我有mvc应用程序.在行动中我有Dictionary<string,int>.的Key是ID和Value是sortOrderNumber.我想创建存储过程,将获取密钥(id)在数据库中查找此记录并从Dictionary中保存orderNumbervalue.我想一次调用存储过程并将数据传递给它,而不是多次调用更新数据.

你有什么想法吗?谢谢!

t-sql sql-server import asp.net-mvc

7
推荐指数
2
解决办法
1万
查看次数

结构化类型必须至少有一个字段 c#

我真正想要做的是我想向 SQL Server 发送一个字符串数组。我正在使用 SQL Server 2008。

这可以标记为重复,但在从 stactoverflow 实施解决方案时,我面临着另一个问题

链接如何将数组传递到 SQL Server 存储过程

这是我的 C# 和存储过程代码

C#代码:

string[] str = new string[] {"s" , "a" , "k"};

DataTable dt = new DataTable();
dt.Columns.Add("names");

foreach (string item in str)
{
    dt.Rows.Add(item);
}

foreach (DataRow r in dt.Rows)
{
    Console.WriteLine(r["names"].ToString());
}

DataTable tvp = new DataTable();

SqlConnection conn = new SqlConnection("Data Source=SHZAK;Initial Catalog=synchroniztionTesing;Integrated Security=True");
conn.Open();

using (conn)
{
    SqlCommand cmd = new SqlCommand("strpdPassAnStringArray", conn);
    cmd.CommandType = CommandType.StoredProcedure;

    SqlParameter …
Run Code Online (Sandbox Code Playgroud)

c# sql-server stored-procedures table-variable

7
推荐指数
1
解决办法
1万
查看次数

使用Enterprise Library从ASP.NET传递(数据表)到SQL Server

     public void updateSkills(DataTable candidateSkillSets)
     {
         string sqlCommand = "Sp_Candidate";
         DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
         db.AddInParameter(dbCommand, "candidateSkillSets",DbType.Object, candidateSkillSets);
         db.ExecuteNonQuery(dbCommand);
     }
Run Code Online (Sandbox Code Playgroud)

我有一个像上面这样的方法,这里我通过添加参数将数据表传递给存储过程."DbType.Object"没有采用数据表类型.我知道在ADO中我们可以使用"SqlDbType.Structured",但对于企业库,它不起作用.我需要用什么呢?

执行命令时出现以下错误

"传入的表格数据流(TDS)远程过程调用(RPC)协议流不正确.参数1("@candidateSkillSets"):数据类型0x62(sql_variant)具有类型特定元数据的无效类型."

c# asp.net enterprise-library

3
推荐指数
1
解决办法
4731
查看次数