我现在遇到这样一个问题,
我的sql语句是
select * from table1 where id in ('id1','id2','id3')
如果使用参数,写成
sqlCommand1.CommandText=@"select * from table1 where id in (@id_list)"; sqlCommand1.Parameters.Add("@id_list",SqlDbType.VarChar);
sqlCommand1.Parameters["@id_list"].Value=@"'id1','id2','id3'"; 那么结果不正确,因为系统会认为我要查找的记录它的id为 'id1','id2','id3'而不是'id1','id2','id3'中的任意一个,
所以我想知道在这种情况下该如何使用参数呢,不会是那种最苯的办法,有多少个可选项,就使用多少个参数吧,即sqlCommand1.CommandText=@"select * from table1 where id in (@id11,@id2,@id3)";
我的sql语句是
select * from table1 where id in ('id1','id2','id3')
如果使用参数,写成
sqlCommand1.CommandText=@"select * from table1 where id in (@id_list)"; sqlCommand1.Parameters.Add("@id_list",SqlDbType.VarChar);
sqlCommand1.Parameters["@id_list"].Value=@"'id1','id2','id3'"; 那么结果不正确,因为系统会认为我要查找的记录它的id为 'id1','id2','id3'而不是'id1','id2','id3'中的任意一个,
所以我想知道在这种情况下该如何使用参数呢,不会是那种最苯的办法,有多少个可选项,就使用多少个参数吧,即sqlCommand1.CommandText=@"select * from table1 where id in (@id11,@id2,@id3)";
解决方案 »
- 数据库操作类写成静态类和非静态类的好处与坏处
- 批量更新数据库的问题 麻烦大家了~
- C#拖动无边框窗体如何实现?
- 向高手求救!对话框调用问题
- 关于DataTable,DataRow的问题
- 求教, 串口实时通信,是windows自身的原因,还是.net的原因??
- 请问我的在debug文件夹下的C#应用程序配置文件每次程序重新编译完后就不见了,要让每次编译后还有怎么办!!!!谢谢了.
- 19寸大小的触摸屏用c#中的什么开发好
- [求助]如何在winform中用c#实现文件中全文检索功能
- 求助,c#制作屏幕截图
- C#可否实现虚拟磁盘的功能
- 关于MSDN上的这边文章 Chapter 11 — Improving Remoting Performance
declare @s varchar(2000)
set @s='select select * from table1 where id in ('+@id_list+')'
exec @s
差不多就是这样了,没验证