温馨提示×

sql中in的参数怎么注入

小新
513
2021-01-14 12:57:17
栏目: 云计算

sql中in的参数怎么注入

sql中in的参数注入示例:

为where in的每一个参数生成一个参数,代码如下:

using (SqlConnection conn = new SqlConnection(connectionString))

{

conn.Open();

SqlCommand comm = new SqlCommand();

comm.Connection = conn;

//为每一条数据添加一个参数

comm.CommandText = "select * from Users(nolock) where UserID in (@UserID1,@UserId2,@UserID3,@UserID4)";

comm.Parameters.AddRange(

new SqlParameter[]{

new SqlParameter("@UserID1", SqlDbType.Int) { Value = 1},

new SqlParameter("@UserID2", SqlDbType.Int) { Value = 2},

new SqlParameter("@UserID3", SqlDbType.Int) { Value = 3},

new SqlParameter("@UserID4", SqlDbType.Int) { Value = 4}

});

comm.ExecuteNonQuery();

}

0