How do I translate a List<string> into a SqlParameter for a Sql In statement?

Posted by KallDrexx on Stack Overflow See other posts from Stack Overflow or by KallDrexx
Published on 2010-12-21T18:50:53Z Indexed on 2010/12/21 18:54 UTC
Read the original article Hit count: 230

Filed under:
|
|

I seem to be confused on how to perform an In statement with a SqlParameter. So far I have the following code:

                cmd.CommandText = "Select dscr from system_settings where setting in @settings";
                cmd.Connection = conn;
                cmd.Parameters.Add(new SqlParameter("@settings", settingList));

                reader = cmd.ExecuteReader();

settingsList is a List<string>. When cmd.ExecuteReader() is called, I get an ArgumentException due to not being able to map a List<string> to "a known provider type".

How do I (safely) perform an In query with SqlCommands?

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql