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:-
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:-
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;
}
Please help me.
thanks