【发布时间】:2018-07-05 19:18:42
【问题描述】:
我正在尝试传递一个字符串 p_strIds,其数值由“,”分隔:
2844099,28441100,2844099,28410.2844105,284411084411111841108441111118411108441111128411128441111128411128441111128411128441111128411141184411115,284111828441115,28411128441115,2841114128441115,284111828441115
字符串用作SqlParameter:
mySqlCommand.Parameters.Add(new SqlParameter("@p_Ids", p_strValores));
由 IN 运算符中的以下资源(添加为资源)查询使用:
UPDATE tbl_Datos
SET col_Leyenda = (select col_Id from tbl_Leyenda where col_Leyenda = 'T')
WHERE col_Id in (@p_Ids)
查询和 IN 运算符应该像这样结束:
UPDATE tbl_Datos
SET col_Leyenda = (select col_Id from tbl_Leyenda where col_Leyenda = 'T')
WHERE col_Id in (2844099,2844100,2844101,2844102,2844103,2844104,2844105,2844106,2844107,2844108,2844109,2844110,2844111,2844112,2844113,2844114,2844115,2844116,2844117,2844118)
但它说它不能将 nvarchar 转换为 int,我如何格式化参数以在 IN(...Ids...) 处使用
如果我将参数 p_strIds 与 string.Format(queryString, p_strIds) 一起使用,它会起作用:
queryString = UPDATE tbl_Datos SET col_Leyenda = (select col_Id from tbl_Leyenda where col_Leyenda = 'T') WHERE col_Id in ({0})
strSql = string.Format(queryString, p_strValores)
mySqlCommand = new SqlCommand(strSql, m_obSqlConnection);
关于如何在第一种方法中使用 sql 语句作为资源的任何想法?
谢谢
【问题讨论】:
-
请阅读有关提问的堆栈溢出指南。这个问题缺少很多上下文细节,无法回答。
标签: sql type-conversion resources sqlparameter