Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello everybody,

[SILVERLIGHT TASK]

I want to display emp_name in the textbox using wcf in silverlight 5.
Below are the codes which is working fine on gridview, but I want display only emp_name in the textbox thats the task.

===============================================

1. MAINPAGE.XAML.CS
C#
private void button1_Click(object sender, RoutedEventArgs e) 
{
ServiceReference1.Service1Client conenction = new ServiceReference1.Service1Client();
conenction.GetEmployeeCompleted += new EventHandler<servicereference1.getemployeecompletedeventargs>(GET_EMP_NAME);
conenction.GetEmployeeAsync();
}
 
 
 
  void GET_EMP_NAME(object sender, ServiceReference1.GetEmployeeCompletedEventArgs e)
        {
            ServiceReference1.Employee emp = new ServiceReference1.Employee();
            //txt_empname.Text = e.Result.ToString();
         //   txt_empname.Text = (string)e.Result.ToList().FirstOrDefault().ToString();
   txt_empname.Text=e.Result.ToList().ToString();      //****THIS IS THE ERROR****//
        DATAGRIDVIEW.ItemSource=e.Result.Tolist(); //****THIS LINE WORKING FINE*****// 

==================================================

2. MY SERVICE CODE HERE. **This service working fine **
C#
[ServiceContract(Namespace = "")]
  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  public class Service1
  {
      string CONENCTIONSTRING = System.Configuration.ConfigurationManager.ConnectionStrings["SWE"].ConnectionString;
      [OperationContract]
      public List<employee> GetEmployee()
      {
         // Employee employee = new Employee();
          List<employee> employee = new List<employee>();
          using (SqlConnection con = new SqlConnection(CONENCTIONSTRING))
          {
              using (SqlCommand CMD = new SqlCommand())
              {
                  CMD.Connection = con;
                  CMD.CommandText = "select EmpName from Employee where EmpNo=101";
                  CMD.CommandTimeout = 600;
                  con.Open();
                  SqlDataReader READER = CMD.ExecuteReader();
                  while (READER.Read())
                  {
                      Employee EMP = new Employee();
                      EMP.EmpNme = READER[0].ToString();
                      employee.Add(EMP);
                  }
              }
          }
          return employee.ToList();

      }

=================================================
3. MY EMPLOYEE CLASS

C#
public class Employee
{
public int EmpNo { get; set; }
public string EmpNme { get; set; }
public string EmpAddres { get; set; }
public int EmpSalary { get; set; }
public int EmpEducation { get; set; }
}

=================================================
Posted
Updated 28-Oct-15 1:28am
v2
Comments
ZurdoDev 28-Oct-15 7:23am    
Put a value in a textbox seems trivial. Where are you stuck?
OriginalGriff 28-Oct-15 7:26am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
Andy Lanng 28-Oct-15 7:30am    
I change it where I see it (and I would leave a comment). That's how I found this little gem http://convertcase.net/ ^_^
OriginalGriff 28-Oct-15 7:34am    
So do I, most times - I have a button in my "Standard replies" application to do it - but in this case he's just being rude and attention seeking! :laugh:
Andy Lanng 28-Oct-15 7:35am    
They usually are >_<
We can only so much :Þ

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