Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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.
Posted

1 solution

If you done every thing correctly, the below line would be binding statement for c#.
C#
this.dataGrid1.ItemsSource = _OrganizationContext.Employees

and for VB.NET is :
VB
Me.dataGrid1.ItemsSource = _OrganizationContext.Employees

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
C#
OrganizationContext _OrganizationContext = new OrganizationContext();

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

-> Bind the data grid on UI with the context
C#
this.dataGrid1.ItemsSource = _OrganizationContext.Employees

-> Load data to context Object
C#
_OrganizationContext.Load(_OrganizationContext.GetEmployeesQuery());

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
C#
_OrganizationContext.Load(_OrganizationContext.GetEmployeesQuery());
this.dataGrid1.ItemsSource = _OrganizationContext.Employees;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900