我有一个像这样的表结构:
user_id | first_name | last_name
1 | John | Smith
2 | Mary | Jones
3 | Sang He | Lau
// here is a sample of the code I currently have to do a user search
public List<string> getResults(string autocompleteQuery) {
string[] tokens = autocompleteQuery.Split(' ');
// token[0] = first name parameter (@firstName)
// token[1] = last name parameter (@lastName)
// code here executes the following query:
// SELECT * FROM [user] WHERE first_name = @firstName AND last_name = @lastName
}
我的问题是,以下使用空格作为列表分隔符并结合查询的代码在名字中有空格时不起作用,如 user_id = 3 所示。
如何优雅地升级代码或查询来处理这种情况?谢谢。