I have 3 tables. The story is: I will choose materials. And which meals can be made with these ingredients.
And this is my c# codes.
string sql = "SELECT * FROM tblmealmaterials WHERE ";
string[] idler = textBox1.Text.Split(',');
for (int i = 0; i < idler.Length; i++)
{
for (int s = 0; s < i; s++)
{
sql +="( materialId= "+ idler[s] + " and materialId= " + idler[i] + " )" ;
if (s<i)
sql += " or ";
}
}
sql += " (";
for (int i = 0; i < idler.Length; i++)
{
sql += " materialId="+ idler[i] ;
if (i<idler.Length-1)
sql += " and ";
}
sql += " )";
richTextBox1.Text = sql;