本文介绍了如何在Silverlight APP中将sql server 2012的数据绑定到datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试在SilverLight应用程序上为SQL Server 2012中的数据库提供数据。

但是,当我在初学者上学习本教程时第16步,我无法找到我的

上下文(教程中的OrganizationContext)从我的数据库中获取数据。



这是教程:

[]



我不知道代码是从我的数据库生成的,是在我的项目中。我试着在本教程的示例中找到上下文,它在样本的HRapp.Web.g.cs文件中是不同的,我无法找到它在窗口浏览器的项目文件夹中的位置。



请有人告诉我如何获取我的上下文以从数据库获取数据或者给我一个提示/指导从SQL2012数据库到SilverLight中的datagrid绑定数据。



P / s:我的英语不好。请原谅我。我尝试了很多教程,但是没有它们指导我如何在SilverLight App中与SQL2012绑定。

Hi everyone,
I am trying to biding data for a database in SQL server 2012 on SilverLight application.
But, when i was following this tutorial for beginner at 16th step, i could not find out my
"context" ( "OrganizationContext" in the tutorial) to get data from my database.

This is that tutorial:
http://code.msdn.microsoft.com/silverlight/Getting-Started-WCF-RIA-1469cbe2[^]

I don''t know where the code, is generated from my database, is in my project. I tried to find "context" in the sample of this tutorial, it''s difinited in HRapp.Web.g.cs file of sample, which i can''t find out where it''s in project folder in window explorer.

Please someone show me how to get my "context" to get data from database or give me a hint/guide to binding data from SQL2012 database to datagrid in SilverLight.

P/s: my English is bad. Please forgive me. And i tried many tutorial but non of them guide me how to binding with SQL2012 in SilverLight App.

推荐答案

this.dataGrid1.ItemsSource = _OrganizationContext.Employees



和VB.NET是:


and for VB.NET is :

Me.dataGrid1.ItemsSource = _OrganizationContext.Employees



它们都位于第16步的编码块中。



*不要忘记初始化

*如果你没有得到你在样本上看到的数据,请从第7步开始检查你的代码

*有些人步骤11和步骤可能有一点问题第12步,如果他们不了解XAML。确保正确执行这些步骤。

*确保数据库中有一些数据



代码的执行流程第16步:

- >首先,它初始化上下文(这可能是你正在寻找的上下文


They both are located in coding block in 16th step.

* Do not forget to initialize it
* If you don''t get the data that you see on the sample, review your code starting from step 7th
* some people might have a little problem with Step 11 & Step 12, if they do not understand XAML. Make sure that you do these steps correctly.
* Make sure you have some data in your database

The execution flow of the code in step 16:
-> First, it initializes the context (this is probably the one that you are looking for

OrganizationContext _OrganizationContext = new OrganizationContext();



- >在Constructure中,它初始化Silverlight组件(在XMAL中定义的东西)


-> In Constructure, it initializes the Silverlight Components (things that defined in XMAL)

InitializeComponent();



- >使用上下文在UI上绑定数据网格


-> Bind the data grid on UI with the context

this.dataGrid1.ItemsSource = _OrganizationContext.Employees



- >将数据加载到上下文对象


-> Load data to context Object

_OrganizationContext.Load(_OrganizationContext.GetEmployeesQuery());



由于dataGrid1的ItemsSource引用了OrganizationContext的Employees属性。所以当你进行_OrganizationContext.Load时,你的数据会被更新,你的视图也应该更新。





如果仍然无效,请尝试


Since ItemsSource of dataGrid1 references to Employees Property of OrganizationContext. So when you do _OrganizationContext.Load you data is updated and so should your view.


If this still does not work, try

_OrganizationContext.Load(_OrganizationContext.GetEmployeesQuery());
this.dataGrid1.ItemsSource = _OrganizationContext.Employees;


这篇关于如何在Silverlight APP中将sql server 2012的数据绑定到datagrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 03:11