我已经采取了一个文本框,一个文本块和一个按钮来执行天蓝色移动服务表中的搜索类型...我在文本框中输入了人的用户名,当我点击按钮时我想获得名字在文本框中,其用户名是在textbox ..m中给出的,所以不知道该怎么做...请帮助我..我试过以下代码,但它不起作用
private async void search_click(object sender, RoutedEventArgs e)
{
MobileServiceCollection<UserData, UserData> data;
IMobileServiceTable<UserData> dataTable = App.MobileService.GetTable<UserData>();
try
{
showBlock.Text = "searching.....";
statusBar.IsIndeterminate = true;
searchButton.IsEnabled = false;
if (searchBox.Text != "")
{
tempUnamePhone = await App.MobileService.GetTable<UserData>().Where(x => x.uname == searchBox.Text || x.phone == searchBox.Text).ToListAsync();
data = await dataTable.Where(x => x.uname == searchBox.Text).Select(x=>x.fname).ToCollectionAsync();
}
if (tempUnamePhone.Count != 0)
{
showBlock.Text = "item found"+fname;
statusBar.IsIndeterminate = false;
searchButton.IsEnabled = true;
}
else
{
showBlock.Text = "no match found";
statusBar.IsIndeterminate = false;
searchButton.IsEnabled = true;
}
}
catch (Exception )
{
var m = new MessageDialog("Network error..close the app and try again" ).ShowAsync();
}
}
}
答案 0 :(得分:0)
var fname = string.Empty;
if (searchBox.Text != "")
{
tempUnamePhone = await App.MobileService.GetTable<UserData>().Where(x => x.uname == searchBox.Text || x.phone == searchBox.Text).ToListAsync();
fname =tempUnamePhone.Where(x => x.uname == searchBox.Text).FirstOrDefault() == null ? string.Empty : await dataTable.Where(x => x.uname == searchBox.Text).First().fname;
此处匹配的记录将作为集合获取。我没有看到从集合中找到fname的代码。我相信fname旨在存储匹配记录中的第一个名字。 您必须检查“数据”中是否返回任何记录,然后将第一条记录分配给“fname&#39;”, 然后设置为文本块
if (tempUnamePhone.Count != 0)
{
showBlock.Text = "item found" + fname;
statusBar.IsIndeterminate = false;
searchButton.IsEnabled = true;
}
else
{
showBlock.Text = "no match found";
statusBar.IsIndeterminate = false;
searchButton.IsEnabled = true;
}