Click here to Skip to main content
15,918,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please Tell me Converted result:

My Sql Query :

select UnivId from University;

But I did Like this:

var v = from i in db.University select i;
Then I got All Columns.
But I Need Only UnivId's.
And Also I need How to Add That UnivId's to List and How to Bind this List result to
ComboBox In SilverLight.

Thanks
vijay
Posted
Comments
vijay4mgvrm 23-Jan-12 10:19am    
I created ClsProperties class with properties Like PUnivId.
I wrote My WcfService Like:
[OperationContract]
public List<clsproperties> UniversityList()
{
List<clsproperties> UnivList = new List<clsproperties>();
DatBaseDataContext db = new DatBaseDataContext();
var v = from i in db.fg0uv000s select new {i.UnivID };
foreach (var i in v)
{
UnivList.Add( new ClsProperties
{
PUnivId=i.UnivID
});
}
return UnivList;
}
Now I consumed service in XAML.cs page with Creation of Event Handler and attach result
to Combobox Like This:
public samplepage()
{
InitializeComponent();
WcfServiceClient client = new WcfServiceClient();
client.UniversityListCompleted+=new EventHandler<universitylistcompletedeventargs>(client_UniversityListCompleted);
client.UniversityListAsync();
}
void client_UniversityListCompleted(object sender, UniversityListCompletedEventArgs e)
{cmbUniversity.ItemsSource= e.Result;}
But I got Result in Combobox like this:
SilverLightApplication.ServiceReference1.ClsProperties
SilverLightApplication.ServiceReference1.ClsProperties
......
Please give me How to Display Actual Values.
Thanks
vijay

 
Share this answer
 
Comments
Espen Harlinn 23-Jan-12 16:03pm    
Excellent article - my 5 :)
try

C#
var v = from i in db.University select i.UnivId;
List<int> list = v.ToList();



but you wouldn't have a description in your combo

so may be you should make a "new" item instead


C#
var v = from i in db.University select new{ Id = i.UnivId, Description = i.Univ};
IList list = v.ToList();
 
Share this answer
 
v2
Comments
vijay4mgvrm 31-Jan-12 0:28am    
Thanks for your answer.. its working

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