private static DataRow CustomDataRow(DataTable tableStructure, DataRow rowWithValue, string refName, int refValue) { DataRow dr = tableStructure.NewRow(); foreach (DataColumn column in tableStructure.Columns) { dynamic columnVal; bool isContain = rowWithValue.Table.Columns.Contains(column.ColumnName); if (isContain) { dynamic columnValue = rowWithValue[column.ColumnName]; CustomValueBind custom = new CustomValueBind(); columnVal = custom.ValueConverter(column.DataType, columnValue); if (columnVal == null) { dr[column.ColumnName] = System.DBNull.Value; } else { dr[column.ColumnName] = columnVal; } } else { if (column.ColumnName == refName) { dr[column.ColumnName] = refValue; } } } return(dr); }
private static DataRow CustomDataRow(DataTable tableStructure, DataRow rowWithValue, int userId) { DataRow dr = tableStructure.NewRow(); foreach (DataColumn column in tableStructure.Columns) { dynamic columnVal = ""; bool isContain = rowWithValue.Table.Columns.Contains(column.ColumnName); if (isContain) { //dynamic columnValue = rowWithValue[column.ColumnName]; //columnValue = columnValue ?? ""; //columnVal = CustomValueBind.ValueConverter(column.DataType, columnValue.ToString()); //dr[column.ColumnName] = columnVal; dynamic columnValue = rowWithValue[column.ColumnName]; CustomValueBind custom = new CustomValueBind(); columnVal = custom.ValueConverter(column.DataType, columnValue); dr[column.ColumnName] = columnVal ?? DBNull.Value; } else { if (column.ColumnName == "UserId") { if (userId > 0) { columnVal = userId; dr[column.ColumnName] = columnVal; } } } } return(dr); }