I wrote a method below, using reflection to load a few strongly typed data into a .NET application. If I worked, as shown below, everything works - including no exceptions. But if I use the comment part (keeping everything else the same), then I get the Constraint inclusion error described here: enter the link description here .
If I look at what is inside the errors array, it is always the following:
"Column 'AEDelegateName' does not allow DBNull.Value."
and ItemArray for the error will look something like this:
[0] = {} [1] = "Some Value"
This surprises me, since I was expecting only 1 column in a script that selects 1 column, not 2, as mentioned above. I also think this is close to the problem, as one of them seems to be null.
My script does not return null, and I can quickly and visually confirm it, and also say that in the query you use, I like NOT NULL .
private void GetData(string query, Component tableAdapter) { OracleCommand command = new OracleCommand(); command.Connection = conn; command.CommandText = query; command.CommandType = CommandType.Text; command.CommandTimeout = 3000; OracleDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult); MethodInfo[] methods = tableAdapter.GetType().GetMethods(); MethodInfo getDataMethod = tableAdapter.GetType().GetMethod("GetData"); DataTable table = (DataTable)getDataMethod.Invoke(tableAdapter, null); Type[] paramTypes = new Type[] { table.GetType() }; MethodInfo updateMethod = tableAdapter.GetType().GetMethod("Update", paramTypes); foreach (DataRow row in table.Rows) { row.Delete(); } //try //{ // if (reader.HasRows) // { // table.Load(reader, LoadOption.OverwriteChanges, FillErrorHandler); // } //} //catch (Exception e) //{ // DataRow[] errors = table.GetErrors(); //} while (reader.Read()) { try { List<object> newRow = new List<object>(); for (int i = 0; i < reader.FieldCount; ++i) { object currentValue = reader.GetValue(i); Debug.WriteLine("Value: "+currentValue); newRow.Add(currentValue); } table.Rows.Add(newRow.ToArray()); } catch (ConstraintException e) { DataRow[] errors = table.GetErrors(); } } updateMethod.Invoke(tableAdapter, new object[]{table}); reader.Close(); }
source share