catttx
catttx

Reputation: 13

C# search query for comma delimited access database field

I'm using Visual Studio to create a C# program with a query that will search a comma delimited access database field for a value.

For example, the database field for one record could be A,B,C or C,B for another record or A for another record. If txtDept = C, the query would be successful in the first two records but not in the third. This is the code I came up with, but Visual Studio gives me an error on txtDept that says "cannot implicitly convert type 'string' to 'bool'".

Is there a way to split the database field before comparing it to txtDept?

Can anyone help me come up with a valid query please?

var courses = from crs in trainingLogDataSet.Course
    where txtDept in crs.Departments
    orderby crs.Date
    select crs;
foreach (var crs in courses)
{
    do something
}

Upvotes: 1

Views: 283

Answers (2)

Leron
Leron

Reputation: 9876

Maybe something like this :

var courses = from crs in trainingLogDataSet.Course
                  where crs.Departments.Contains(txtDept)
                  orderby crs.Date
                  select crs

Upvotes: 0

crthompson
crthompson

Reputation: 15875

Your error appears to be coming from your where clause.

where txtDept in crs.Departments should be where crs.Departments.Contains(txtDept)

Upvotes: 1

Related Questions