我已经写了一个简单的Web服务,允许我插入到我的SQL DB(工作正常),并从我的SQL DB(目前不工作)检索信息。我试图将信息放入列表中,然后将该信息显示在通用Windows应用程序的列表框中。此登录我:从WebService LINQ查询填充列表框
WEB SERVICE
[OperationContract]
List<TBL_My_Info> FindInfo(string uid);
public List<TBL_My_Info> FindInfo(string uid)
{
DataClasses1DataContext context = new DataClasses1DataContext();
var res = from r in context.TBL_My_Info where r.User_Name == uid select r;
return res.ToList();
}
通用web应用
private void btnView_Click(object sender, RoutedEventArgs e)
{
string s = txtNameFind.Text;
this.Content = new Page1(s);
}
public Page1(string s)
{
this.InitializeComponent();
LoadData(s);
}
private async void LoadData(string s)
{
var client = new ServiceReference1.Service1Client();
var res = await client.FindMyInfoAsync(s);
articleMyInfoListBox.ItemsSource = res;
}
XAML
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListBox x:Name="articleMyInfoListBox"></ListBox>
</Grid>
我知道我需要像myListBox.ItemSource = res;
这样的东西,但res在ItemSource
之后没有显示为选项。我使用using myapp.ServiceReference1;
引用了我的Web服务。
因此,在短期,我所希望做的是填充列表框的信息返回的列表,了解这些信息是从Web服务来....
如果我这样做的错误的方式,并有更好的方式,请让我知道。我对LINQ没有任何经验,但对SQL有一定的经验。所以,当然,SQL将是可取的..
编辑
我目前得到这回在我的列表框
using InsertAppTest.ServiceReference1.TBL_My_Info;
好了,我调试的代码将您的建议在后,以及在将数据通过“res”变量,但不显示它在列表框中。相反,在列表框中,它显示我在页面顶部使用的语句“using myapp.ServiceReference1”,并将该表添加到using语句的末尾......因此,在整个列表框中都返回这个“使用myapp.ServiceReference1.TBL_My_Info”...我将在上面发布更新后的代码,以及列表框的xaml。有什么建议? – Code
我只是将编辑添加到我的问题 – Code
当它呈现时,您的列表框的内容实际上是字符串“using myapp.ServiceReference1.TBL_My_Info”?这没有意义。您是否将列表框的DisplayMemberPath属性设置为TBL_My_Info类中属性的名称? – alexchardin