public DataTable ToDataTable(ITable mTable)
{
try
{
DataTable pTable = new DataTable();
for (int i = 0; i < mTable.Fields.FieldCount; i++)
{
string columName = mTable.Fields.get_Field(i).Name;
if (columName.Contains("FID") || columName.Contains("OBJECTID"))
pTable.Columns.Add(columName, typeof(System.Int32));
else if (columName.Contains("shape_area") || columName.Contains("shape_len") || columName.Contains("shape_leng"))
pTable.Columns.Add(columName, typeof(System.Double));
else
{
pTable.Columns.Add(columName);
}
}
ICursor pCursor = mTable.Search(null, false);
IRow pRrow = pCursor.NextRow();
while (pRrow != null)
{
DataRow pRow = pTable.NewRow();
object[] array = new object[pRrow.Fields.FieldCount];
for (int i = 0; i < pRrow.Fields.FieldCount; i++)
{
array[i] = pRrow.get_Value(i);
}
pRow.ItemArray = array;
pTable.Rows.Add(pRow);
pRrow = pCursor.NextRow();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor);
return pTable;
}
catch (Exception ex)
{
return null;
}
}