Event A on interface type B for instance id C cannot be delivered
This post reminded me to mark classes as serializable.
Event A on interface type B for instance id C cannot be delivered
////// Convert the xml string into a DataSet object /// /// The xml string to convert ///The DataSet instance public DataSet ConvertXmlToDataSet(string xml) { using (StringReader reader = new StringReader(xml)) { using (XmlTextReader xmlReader = new XmlTextReader(reader)) { DataSet dataSet = new DataSet(); dataSet.ReadXml(xmlReader); return dataSet; } } } ////// Converts a DataSet into an xml string representation /// /// The DataSet to convert ///The xml string representation of the DataSet public string ConvertDataSetToXml(DataSet dataSet) { using (StringWriter writer = new StringWriter()) { using (XmlTextWriter xmlTextWriter = new XmlTextWriter(writer)) { dataSet.WriteXml(xmlTextWriter); return writer.ToString(); } } }
public void LoadData()
{
IList employees = new List();
DataTable result = // Get data from SP
foreach (DataRow row in result.Rows)
{
Employee employee = new Employee();
employee.Id = GetColumnData<int>("EMP_ID", row, null);
employee.Name = GetColumnData<string>("EMP_NAME", row, "Unknown");
employee.Salary = GetColumnData<decimal>("EMP_SALARY", row, null);
employees.Add(employee);
}
}
///
/// Gets data from a column checks it can convert it correctly if no data or invalid casting the default
/// value is returned
///
/// The type of data to convert too
/// The name of the column in the row
/// The row containing the data
/// The default value
/// The data or the default value
public static T GetColumnData<T>(string columnName, DataRow row, object defaultValue)
{
if (row.Table.Columns.Contains(columnName) && row[columnName] != DBNull.Value)
{
string value = row[columnName].ToString();
TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
object result = converter.ConvertFromString(value);
try
{
return (T)result;
}
catch (InvalidCastException)
{
return (T)defaultValue;
}
}
else
{
return (T)defaultValue;
}
}