Reputation: 13
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
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
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