using IN condtion in SQL CE

158 Views Asked by At

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 ?

0

There are 0 best solutions below