在 TdParameter 中使用 'IN' 子句

Using 'IN' Clause in TdParameter

我正在尝试使用 C# 代码连接到 Teradata。我需要使用 IN 子句执行 Select 语句,并且我需要动态传递值。

例如:

TdCommand cmd = conn.CreateCommand();
cmd.CommandText = "Select EmpNum,EmpName from Employee where EmpName IN (?)";

我需要使用 TdParameter 来设置 IN 子句的值。它可以是一个或多个名称。这是 Web API 的一部分,我从 API 输入中收到姓名列表。

有人可以指导我如何完成这个吗?

我使用 .Net 4.5 和 Teradata dll 版本 15.11。如果您需要更多详细信息,请告诉我。

我想不出比这更好的解决方案了。

List<string> employeeNames = APICall();
cmd.CommandText = "Select EmpNum,EmpName from Employee where EmpName 
                   IN (\"" + String.Join("\",\"", employeeNames) + "\")";

cmd.CommandText = "Select EmpNum,EmpName from Employee where EmpName 
                   IN ('" + String.Join("','", employeeNames) + "')";

用于单引号

这将保留引号。让我知道这个是否奏效。

TdParameter 有一个允许的类型列表(TdType - https://developer.teradata.com/doc/connectivity/tdnetdp/15.11/help/Teradata.Client.Provider~Teradata.Client.Provider.TdType.html),数组不是其中之一。