请教下各位老师,在Parameters加入了一个参数,但是这个参数的值是可变的字符串数组

今天天气不错123 2017-07-19 05:23:57
请问这样写可以吗,执行不出来数据,但是在后台执行是有数据的,请问哪里错了,麻烦有老师帮我看看吗,谢谢。


public DataTable SelectTaxPayer(params string[] custid)
{
string tmpcust_id = null;
for (int i = 0; i < custid.Length; i++)
{
if (i < custid.Length - 1)
{
tmpcust_id += "'" + custid[i] + "',";
}
else
{
tmpcust_id += "'" + custid[i] + "'";
}
}
OracleConnection conn = new OracleConnection(LoginUtil.ConnStr);
string sqlText = " select * " +
" from table_tmp " +
" where to_char(cust_id) in (:custid) ";
OracleCommand cmd = new OracleCommand(sqlText,conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new OracleParameter("custid", OracleType.VarChar, 200));
cmd.Parameters.AddWithValue("custid", tmpcust_id);
//TaxPayerModel taxpayer = null;
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();


try
{
conn.Open();
da.Fill(ds);
return ds.Tables[0];

}
catch (Exception ex)
{
return null;
}
finally
{
conn.Close();
}

}
...全文
158 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
谢谢,觉得不是最好的办法,只有一个一个来了,谢谢。
xdashewan 2017-07-19
  • 打赏
  • 举报
回复
循环拼接sql,如" where to_char(cust_id) in (:custid1, :custid2,......) ,Parameters做同样添加N个

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧