我从数据库中查询两个表并将唯一值添加到通用列表中。
如果有一个我不想添加到列表中的值,我该如何防止该项目被添加?
using (myOledbConn = new OleDbConnection(connAccessLrProduct))
{
List<string> lst = new List<string>();
myOledbConn.Open();
OleDbCommand cmd = myOledbConn.CreateCommand();
cmd.CommandText = @"SELECT tblProducts.CODE, tblSubject.SUBJECT, tblProducts.GenSubject
FROM tblSubject INNER JOIN tblProducts ON tblSubject.ID = tblProducts.SubjectID
WHERE [SUBJECT] = 'Arts' or [SUBJECT] = 'Aged Care';";
OleDbDataReader dbReader = cmd.ExecuteReader();
while (dbReader.Read())
{
string generalSublject;
string subject = (string)dbReader["SUBJECT"];
if (lst.Where(t => t == subject).Count() == 0)
lst.Add(subject);
if (dbReader["GenSubject"] != DBNull.Value)
{
generalSublject = (string)dbReader["GenSubject"];
if(generalSublject.Equals("No related topics"))
{
//how do I exclude this item from being added to the list?
}
if (lst.Where(t => t == generalSublject).Count() == 0)
lst.Add(generalSublject);