private DataTable ConvertRFCTabletoDataTable(IRfcTable table) { try { DataTable resultTable = new DataTable(); for (int i = 0; i < table.Metadata.LineType.FieldCount; i++) { resultTable.Columns.Add(table.Metadata.LineType[i].Name); } for (int i = 0; i < table.RowCount; i++) { table.CurrentIndex = i; DataRow row = resultTable.NewRow(); foreach (DataColumn item in resultTable.Columns) { //edited by kevin at 2011-09-23 #region 把RFCTable的值转换成DataSet的值 if (table.Metadata.LineType[item.ColumnName].DataType.ToString() == "BCD") //BCD为值类型 { row[item.ColumnName] = table.GetDecimal(item.ColumnName); } else { row[item.ColumnName] = table.GetObject(item.ColumnName); } #endregion } resultTable.Rows.Add(row); } return(resultTable); } catch (RfcCommunicationException e) { // network problem... //throw new Exception("network problem", e); throw new Exception(e.Message, e); } catch (RfcAbapRuntimeException e) { // serious problem on ABAP system side... //throw new Exception("serious problem on ABAP system side", e); throw new Exception(e.Message, e); } catch (RfcAbapBaseException e) { // The function module returned an ABAP exception, an ABAP message // or an ABAP class-based exception... //throw new Exception("The function module returned an ABAP exception, an ABAP message or an ABAP class-based exception...",e); throw new Exception(e.Message, e); } catch (RfcBaseException e) { throw e; } catch (Exception ex) { throw new Exception(message + ex.Message); } }