我是新来的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