データベースから 2 つのテーブルをクエリし、一意の値を一般的なリストに追加します。
リストに追加したくない値がある場合、その項目が追加されないようにするにはどうすればよいですか?
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);