SQL query with " IN " function with C# List

Tuesday, April 8, 2014
Here uLL is the List<BsonValue> ,because i am using MongoDB as a Database.
that's why i did convert to List<int> for compare with SQL.


string qry = "select count(*) from SendMessageHistory where SendDate> convert(varchar(10), getdate(),120) ";

                if (td != 1)
                {
                    if (td == 0)
                    {
                        qry += "and UserID=" + userID;
                    }
                    else if (td == 2)
                    {
                        AccountData dad = new AccountData();
                        var uLL = dad.GetUserByManagerID(userID);
                        List<int> ul=new List<int>();
                        foreach (var user in uLL)
                        {
                            ul.Add(Convert.ToInt32(user));
                        }
                         string types = string.Join(",", ul.ToArray());
                         qry += "and UserID In (" + types + ")";
                    }
                 
                }

0 comments:

Post a Comment