0

How we can we pass list of values as parameters in SQLCE?

using the below code works (when directly passing list of values in query)

    SqlCeCommand cmd = string.Format("Select VMID from Booking where (VMID in ({0})", 
                       selectedVMs );
    SqlCeManager.OpenSqlConnection();//my custom code to open sql connection
    sqlCmd = new SqlCeCommand(cmd, SqlCeManager.sqlConn);

But the below code does not work ( when passing the list of values using the parameters).

    SqlCeCommand cmd = "Select VMID from Booking where (VMID in (@VMIDs))";
    SqlCeManager.OpenSqlConnection();//my custom code to open sql connection     
    sqlCmd.Parameters.Add("@VMIDs", string.Join(",", selectedVMs));
    sqlCmd = new SqlCeCommand(cmd, SqlCeManager.sqlConn);

The error i get is "@IDs : 8,7 - Input string was not in a correct format."

What am i missing here ?

Ram
  • 15,908
  • 4
  • 48
  • 41
  • 3
    Your missing that there's a logical difference between providing two parameters to `IN()`, separated by commas, versus providing a *single* parameter to `IN()` that happens to be a string that contains a comma. – Damien_The_Unbeliever Jan 16 '13 at 10:39
  • @Damien_The_Unbeliever I think you are right and it makes sense. Thanks for your quick post. – Ram Jan 17 '13 at 01:59
  • Looking for a cleaner way to pass a list of values using parameters option. – Ram Jan 18 '13 at 04:25
  • For full-blown SQL Server, I'd recommend table-values parameters. I'm not sure if CE supports those (and if so, on which versions) – Damien_The_Unbeliever Jan 18 '13 at 06:45

0 Answers0