Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I am trying to get my query, to be able to search multiple values of 'tag' fieldname in one textbox. I am little unclear what is correct approach for this task. I have started by adding split to the linq query below, however this is approach keeps throwing me a compiling error such as:

Argument 1: cannot convert from 'string[]' to 'string' --> error

Updated Code:
C#
public ActionResult Search(string search, string type, string cover, string sin, string cus)
{
    DateTime yesterday = DateTime.Today.AddBusinessDays(-1);

    var query = from s in db.data_qy
               where s.UploadDate == yesterday
               select (s);

    if (!String.IsNullOrEmpty(cover))
    {
        query = query.Where(s => s.Cover == cover);
    }

    if (!string.IsNullOrEmpty(cus))
    {
        string [] ids = cus.Split(',');

        query = query.Where(c => c.TAG.Contains(ids)); //error
    }
   // var data = query.ToList();
    return View(query);
}

Any help would be very much appreciated. Many thanks.
Posted
Updated 12-May-14 3:47am
v3

1 solution

Change
C#
string ids = cus.Split(',');

C#
string [] ids = cus.Split(',');
 
Share this answer
 
v3
Comments
miss786 12-May-14 7:49am    
Apology for not clarifying earlier, but I already tried this method and it throws many compiling issues such as:
Cannot implicitly convert type 'string[]' to 'var[]' -- error.
The best overloaded method match for 'string.Contains(string)' has some invalid arguments -- error.

Please advice, if possible. Thank you
miss786 12-May-14 9:11am    
apology for the late response. I am sorry to inform, I am still getting the same error on the 'contain' clause:

cannot convert from 'string[]' to 'string' --> error

please advice, if possible. Thank you very much for your feedback.
Vi(ky 12-May-14 9:20am    
can you paste your code
miss786 12-May-14 9:25am    
thank you for your quick response. I have posted my updated code above. Many thanks.
Vi(ky 12-May-14 9:43am    
Contains() has no overload method to accept array. You can not pass string array to Contains()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900