public static void WriteSelectionScratchTable(DataColumn[] targetColumns, DataTable idList) { try { int incidOrdinal = -1; if (idList.Columns.Contains(_incidTable.incidColumn.ColumnName)) { if (idList.Columns[_incidTable.incidColumn.ColumnName].DataType == _hluLayerStructure.incidColumn.DataType) { incidOrdinal = idList.Columns[_incidTable.incidColumn.ColumnName].Ordinal; } else { return; } } else { var q = idList.Columns.Cast <DataColumn>().Where(c => c.ColumnName.EndsWith( Resources.ColumnTableNameSeparator + _incidTable.incidColumn.ColumnName) && c.DataType == _incidTable.incidColumn.DataType); if (q.Count() == 1) { incidOrdinal = q.ElementAt(0).Ordinal; } else { return; } } // incid column always has the same name as in the GIS layer structure if (idList.Columns[incidOrdinal].ColumnName != _hluLayerStructure.incidColumn.ColumnName) { idList.Columns[incidOrdinal].ColumnName = _hluLayerStructure.incidColumn.ColumnName; } try { _scratchDb.ExecuteNonQuery(String.Format("DROP TABLE {0}", _scratchSelTable), _scratchDb.Connection.ConnectionTimeout, CommandType.Text); } catch { } if (String.IsNullOrEmpty(idList.TableName)) { idList.TableName = _scratchSelTable; } if ((idList.PrimaryKey == null) || (idList.PrimaryKey.Length == 0)) { idList.PrimaryKey = new DataColumn[] { idList.Columns[incidOrdinal] } } ; if (!_scratchDb.CreateTable(idList)) { return; } DataTable scratchTable = idList.Clone(); DataSet datasetOut = new DataSet(_scratchSelTable); IDbDataAdapter adapterOut = _scratchDb.CreateAdapter(scratchTable); adapterOut.Fill(datasetOut); adapterOut.TableMappings.Clear(); adapterOut.TableMappings.Add(scratchTable.TableName, datasetOut.Tables[0].TableName); scratchTable = datasetOut.Tables[0]; foreach (DataRow r in idList.Rows) { scratchTable.LoadDataRow(r.ItemArray, false); } adapterOut.Update(datasetOut); } catch { } finally { if ((_scratchDb != null) && (_scratchDb.Connection.State != ConnectionState.Closed)) { try { _scratchDb.Connection.Close(); } catch { } } } }