C# 帮助构建要查询的 where 子句
我是 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< /代码>
i am newbie in c#,
i want to build query string , i do some conditions , every condition add another condition to where clause
i want something like that :
// 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;
but i do not know exactly how to declare all the variables like where_arr
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)