62,046
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
Console.WriteLine(GetEntity("table1", new string[] { "column1", "column2" }, new string[] { "value1", "value2" }));
}
static string GetEntity(string tableName, string[] columns, string[] values)
{
if (columns.Length != values.Length)
return "";
if (columns == null || values == null || columns.Length == 0)
return "select * from " + tableName;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < columns.Length; i++)
sb.Append(columns[i] + "='" + values[i] + "' and ");
return "select * from " + tableName + " where " + sb.ToString().Substring(0, sb.ToString().LastIndexOf("and"));
}