History: I have a small site in PHP which I wanted to make a better front end for. Having looked around, spending an hour or so on each of FlashBuilder etc., I found Silverlight 4 the quickest to get moving with, but I have hit an issue.
I have a class for simplicity
public partial class data
{
public String Software;
public int OK;
public int warn;
public int falsepos;
public int failed;
public int total;
}
I then load the class using a call to my service going something like:
[OperationContract]
public List<data> GetSum(){
String sql="SELECT Software, OK, warn, falsepos, failed from sum";
List<data> res = new List<data>();
if (!DBConnect()) { throw new Exception("Unable to contact Database"); }
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sql, _sqlConnection);
DataSet ds = new DataSet();
da.Fill(ds);
_sqlConnection.Close();
foreach (DataRow dr in ds.Tables[0].Rows)
{
data d = new data();
d.Software = dr["software"].ToString();
d.OK = Int16.Parse(dr["OK"].ToString());
d.warn = Int16.Parse(dr["Warning"].ToString());
d.falsepos = Int16.Parse(dr["False Positive"].ToString());
d.failed = Int16.Parse(dr["Failed"].ToString());
d.total = d.OK+d.warn+d.falsepos+d.failed;
res.Add(d);
}
return res;}
Now, that compiles fine, except, the moment I add the foreach
, it starts falling apart,
private void Summary(object Sender, ServiceProxy.GetSumCompletedEventArgs e)
{
foreach (data d in e.Result)
{
}
}
The moment I go to parse through the list as a result, it says
Error 2 foreach statement cannot operate on variables of type 'SilverlightApplication1.ServiceProxy.GetSumResponse' because 'SilverlightApplication1.ServiceProxy.GetSumResponse' does not contain a public definition for 'GetEnumerator' C:\Users\me\Documents\Visual Studio 2010\Projects\SilverlightApplication1\SilverlightApplication1\Page1.xaml.cs 52 13 SilverlightApplication1
Now, I've looked around and read and seen a number of things, now, a very very similar function which just returns a list of servernames, works. Because I guess it's of type String, however, I understand it's not generated the how to read the single item within the list, but this is bugging me. I just want to return a simple list of stuff. Can someone please point me in the right direction?
I'm sure it's something simple. Like an attribute, or something, but this seems silly that I can't find the answer, be kind, I've only been looking at Silverlight for a couple of hours.