Click here to Skip to main content
16,017,373 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,
I have a silverlight app in which i consume WCF service for showing record from database.
data is passed from WCF to Silvelight in List<> having store in class variable.
but when i am binding the result with datagrid of silverlight then an error:-

Error 1 Cannot implicitly convert type 'AdWorldSilverLightApp.ServiceReference1.fetchUserRecordResponseFetchUserRecordResult' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?) F:\balwant\TestApp\AdWorldSilverLightApp\AdWorldSilverLightApp\ShowUser.xaml.cs 43 36 AdWorldSilverLightApp


occurs.
silverlight xaml.cs code is as:-
C#
public ShowUser()
       {
           InitializeComponent();
           ServiceReference1.MyServiceClient newclient = new ServiceReference1.MyServiceClient();
           newclient.fetchUserRecordCompleted += new EventHandler<ServiceReference1.fetchUserRecordCompletedEventArgs>(newclient_fetchUserRecordCompleted);
           newclient.fetchUserRecordAsync();
       }
       void newclient_fetchUserRecordCompleted(object sender, ServiceReference1.fetchUserRecordCompletedEventArgs e)
       {

           ShowGrid.ItemsSource = e.Result;
       }



and WCF service code is as:-
C#
public class UserMaster
       {
           public string UserName { get; set; }
           public string Password { get; set; }
           public string FirstName { get; set; }
           public string LastName { get; set; }
           public string Email { get; set; }
           public string Address { get; set; }
           public string MatrialStatus { get; set; }
           public string Moblie { get; set; }
       }
 public List<UserMaster> fetchUserRecord()
        {
            var Record = new List<UserMaster>();
            SqlConnection con = new SqlConnection();
            con.ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            con.Open();
            cmd.CommandText = "select * from UserMaster";
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i <= dt.Rows.Count; i++)
                {
                    var user = new UserMaster
                    {
                        UserName = dt.Rows[i]["UserName"].ToString(),
                        Password=dt.Rows[i]["Password"].ToString(),
                        FirstName = dt.Rows[i]["FirstName"].ToString(),
                        LastName = dt.Rows[i]["LastName"].ToString(),
                        Email = dt.Rows[i]["Email"].ToString(),
                        Address = dt.Rows[i]["Address"].ToString(),
                        MatrialStatus = dt.Rows[i]["MatrialStatus"].ToString(),
                        Moblie = dt.Rows[i]["Moblie"].ToString()
                    };
                    Record.Add(user);


                }
                
            }
          
            return Record;
            // return dt;
        }

Please help me.
thanks
Posted
Updated 26-Apr-11 20:23pm
v2
Comments
walterhevedeich 27-Apr-11 2:23am    
corrected misplaced pretags.

1 solution

You cannot just set the itemsource to the result - ShowGrid.ItemsSource = e.Result;.

You need to remove put the values returned in the result into a collection (an IEnumerable object) and the assign to the itemssource.
Check what you are getting in e.Result - is it an IEnumerable type?
 
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