Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to return the value using the following method:
C#
public string GetAge(string myName)
        {
            DataClasses1DataContext data = new DataClasses1DataContext();
            var myAge = from a in data.Users where a.uName == myName select a;
            return myAge.ToString();
        }

But the returned value in the textblock is: "SELECT [t0].[Id], [t0].[uName], [t0].uAge..."
The WP code is:
C#
private void Button_Click(object sender, RoutedEventArgs e)
       {
           ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
           proxy.GetAgeCompleted += SetAgeText;
           string myName = "Nick";
           proxy.GetAgeAsync(myName);
       }

       private void SetAgeText(object sender, ServiceReference1.GetAgeCompletedEventArgs e)
       {
           AgeTxtBlck.Text = e.Result;
       }

Could you correct this code please.
Posted

1 solution

In your GetAge method you build the query but forget to run it.
So you should change your code like this:
C#
public string GetAge(string myName)
        {
            DataClasses1DataContext data = new DataClasses1DataContext();
            var myAge = from a in data.Users where a.uName == myName select a;
            User user = myAge.FirstOrDefault(); //Run the query!!!
            return (user == null ? null : user.uAge.ToString()); //Return the user age as string!
        }
 
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