I have a web service that should return the top 5 letters in my mailbox and display them in the data grid. At first I put my data in a DataTable
. But keep getting errors
Here is my code: did I miss something or proclaim something is wrong?
[WebMethod] public DataTable DisplayMailList(String inMailServer, String inPort, bool inSSlCheck, String inUsername, String inPassword) { objClient.Connect(inMailServer, int.Parse(inPort), inSSlCheck); objClient.Authenticate(inUsername, inPassword); int count = objClient.GetMessageCount(); DataTable dtMessages = new DataTable(); // Creating datatable. dtMessages.Columns.Add("MessageNumber"); dtMessages.Columns.Add("From"); dtMessages.Columns.Add("Subject"); dtMessages.Columns.Add("DateSent"); dtMessages.TableName = "dtMessages"; int counter = 0; for (int i = count; i >= 1; i--) { OpenPop.Mime.Message msg = objClient.GetMessage(i); dtMessages.Rows.Add(); dtMessages.Rows[dtMessages.Rows.Count - 1]["MessageNumber"] = i; //Populateing Datatable dtMessages.Rows[dtMessages.Rows.Count - 1]["Subject"] = msg.Headers.Subject; dtMessages.Rows[dtMessages.Rows.Count - 1]["DateSent"] = msg.Headers.DateSent; counter++; if (counter > 5) { break; } } return dtMessages; }
Think of the issue as a publicly accessible DataTable . I declared it as an object, but it did not work on the air ... sigh, what should I declare as? this is mistake....
Fix System.InvalidOperationException: An error occurred that generated the XML document. ---> System.InvalidOperationException: DataTable cannot be serialized. The name DataTable is not set.
source share