私はC#の初心者です。
クエリ文字列を作成したいのですが、いくつかの条件を実行し、すべての条件が where 句に別の条件を追加します
私はそのようなものが欲しい:
// BUILD SELECT QUERY
string where = "";
string[] where_arr = new string[];
if (condition1)
{
where_arr[index++] = " field = 5 ";
}
if (condition2)
{
where_arr[index++] = " field2 = 7 ";
}
if (where_arr.Count>0)
where = " where" + String.Join(" and ", where_arr);
string sql = "select count(*) as count from mytable " + where;
しかし、次のようなすべての変数を宣言する方法が正確にはわかりませんwhere_arr