How to convert this COUNT to INT? - c#

string query = "SELECT COUNT(DISTINCT [PIN]) AS [pinCount] FROM [Users]";
DataTable dt = Execute(query);
if (dt == null || dt.Rows.Count == 0 || dt.Rows[0][0] == DBNull.Value)
return false;
else if ((int)dt.Rows[0]["pinCount"] > 0)
return true;
return false;
i have this kind of query in my code, and when casting the count to int, it gives me an exception that when castin the value must be less then infinite...what am i doing wrong?

Try this code
if (dt != null)
{
if (dt.Rows.Count > 0)
{
object tVal = dt.Rows[0][0];
if (!Convert.IsDBNull(tVal))
return (Convert.ToInt32(tVal) > 0);
}
}
return false;

Related

How should NULL properties be handled in a CompareTo method?

I want to compare 2 instances of a class to see if they are equal.
I created this method that is faulty:
public int CompareTo(AdminEngineTableRowModel other)
{
int result;
if (other != null)
{
result = NXSTDT.CompareTo(other.NXSTDT);
if (result == 0)
result = DALOC.CompareTo(other.DALOC);
if (result == 0)
result = DealerID.CompareTo(other.DealerID);
if (result == 0)
result = Status.CompareTo(other.Status);
if (result == 0)
result = OrderNumber.CompareTo(other.OrderNumber);
if (result == 0)
result = Dealership.CompareTo(other.Dealership);
if (result == 0)
result = Serial.CompareTo(other.Serial);
if (result == 0)
result = Model.CompareTo(other.Model);
if (result == 0)
result = OrderDate.CompareTo(other.OrderDate);
if (result == 0)
result = StartDate.CompareTo(other.StartDate);
if (result == 0)
result = Confirmed.CompareTo(other.Confirmed);
if (result == 0)
result = Deposit.CompareTo(other.Deposit);
if (result == 0)
result = Engine.CompareTo(other.Engine);
if (result == 0)
result = Color.CompareTo(other.Color);
if (result == 0)
result = Name.CompareTo(other.Name);
}
else
{
result = 1;
}
return result;
}
The problem comes when any of the properties, like the first string NXSTDT is NULL:
result = NULL.CompareTo(other.NXSTDT); // This causes an error
I could create a class ctor constructor to initialize all of the properties, or I could edit the CompareTo method to check that each property is not null before I test it:
public int CompareTo(AdminEngineTableRowModel other)
{
int result;
if (other != null)
{
if ((NXSTDT == null) && (other.NXSTDT != null))
result = 1;
if (result == 0)
result = NXSTDT.CompareTo(other.NXSTDT);
if ((DALOC == null) && (other.DALOC != null))
result = 1;
if (result == 0)
result = DALOC.CompareTo(other.DALOC);
// {snip}
}
else
{
result = 1;
}
return result;
}
That just seems like poor programming.
Is there a better way to do this?
One idea would be to write a generic Compare<T> method that works will any object that implements IComparable<T>. Then you can write the null-handling once and not worry about it again. This does assume that the types you're comparing implement that interface.
public static int Compare<T>(T first, T second) where T : IComparable<T>
{
if (ReferenceEquals(first, second)) return 0;
if (first == null) return -1;
return first.CompareTo(second);
}
Then your code would look like:
public int CompareTo(AdminEngineTableRowModel other)
{
if (ReferenceEquals(this, other)) return 0;
if (other == null) return 1;
int result = Compare(NXSTDT, other.NXSTDT);
if (result != 0) return result;
result = Compare(DALOC, other.DALOC);
if (result != 0) return result;
result = Compare(DealerID, other.DealerID);
if (result != 0) return result;
result = Compare(Status, other.Status);
if (result != 0) return result;
result = Compare(OrderNumber, other.OrderNumber);
if (result != 0) return result;
result = Compare(Dealership, other.Dealership);
if (result != 0) return result;
result = Compare(Serial, other.Serial);
if (result != 0) return result;
result = Compare(Model, other.Model);
if (result != 0) return result;
result = Compare(OrderDate, other.OrderDate);
if (result != 0) return result;
result = Compare(StartDate, other.StartDate);
if (result != 0) return result;
result = Compare(Confirmed, other.Confirmed);
if (result != 0) return result;
result = Compare(Deposit, other.Deposit);
if (result != 0) return result;
result = Compare(Engine, other.Engine);
if (result != 0) return result;
result = Compare(Color, other.Color);
if (result != 0) return result;
return Compare(Name, other.Name);
}
If you just want to compare 2 instances for equality, it is simpler to use a boolean Equals() method, like so:
public bool Equals(AdminEngineTableRowModel other)
{
if (other == null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
// If applicable, use <Property>.Equals(other.<Property>)
// For example, to compare strings according to culture
// and case
return (NXSTDT == other.NXSTDT &&
DALOC == other.DALOC &&
DealerId == other.DealerId &&
Status == other.Status &&
OrderNumber == other.OrderNumber &&
....);
}
This way, due to short-circuiting, the method will return false on the first un-equal property value.
If you use at least C# 9 you don't need to actually implement anything, just add record keyword to your class:
public record class YourClass {}
it will automatically generate the Equals, GetHashCode methods among others and overload the == operator so you can simply do:
if (instanceA == instanceB) {}
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/records

How to make this if statement with multiple conditions shorter?

I began fixing a problem the customer had with signatures not displaying correctly. The customer has 2 columns one for current and for prior times - so they can have five outcomes:
Current new These two we just need to show the CurrDate
Prior New This hits the 1st ret
Current New This hits the 3rd ret
Prior Null
Current old These three we need to show the PrevDate
Prior old This hits the 2nd ret
Current new This hits the 2nd ret
Prior old
Current old This hits the 4th ret
Prior null
I and got to this if statement
private string CheckBoxDescription()
{
if (ViewState["PrevDate"] != null &&
ViewState["PrevDate"].ToString().Trim() != "" &&
ViewState["CurrDate"] != null &&
ViewState["CurrDate"].ToString().Trim() != "")
{
if (DateTime.Parse(ViewState["PrevDate"].ToString()) >
DateTime.Parse("01-JAN-12") &&
DateTime.Parse(ViewState["CurrDate"].ToString()) >
DateTime.Parse("01-JAN-12"))
{
return "SELECT Statement to get CurrDate;
}
else
{
return "SELECT Statement to get PrevDate;
}
}
if (DateTime.Parse(ViewState["CurrDate"].ToString()) >
DateTime.Parse("01-JAN-12"))
{
return "SELECT Statement to get CurrDate (Same as the CurrDate above);
}
else
{
return "SELECT Statement to get PrevDate (Same as the PrevDate above);
}
}
I tried this:
if (DateTime.Parse(ViewState["CurrDate"].ToString()) >
(DateTime.Parse("011-JAN-12")) &
(DateTime.Parse(ViewState["PrevDate"].ToString()) >
(DateTime.Parse("011-JAN-12")) |
(DateTime.Parse(ViewState["PrevDate"].ToString()) !=
null)))
but it will not pick up one of the null values.
For the null/empty check you can use String.IsNullOrWhitespace:
if (!string.IsNullOrWhiteSpace(ViewState["PrevDate"]) &&
!string.IsNullOrWhiteSpace(ViewState["CurrDate"]))
I would also store the parsed dates in variables rather than parsing each time
DateTime minDate = new DateTime(2012,1,1);
DateTime prevDate = DateTime.Parse(ViewState["PrevDate"]));
DateTime currDate = DateTime.Parse(ViewState["CurrDate"]));
then use those in the comparisons:
if (prevDate > minDate &&
currDate > minDate)
For the last check, DateTime.Parse will never return null so I'm not sure what conditions you're trying to check there. If the string value could be null then just check that:
if (currDate > minDate &
(ViewState["PrevDate"] == null ||
prevDate > minDate)
)
private string CheckBoxDescription()
{
if (ViewState["PrevDate"] != null &&
ViewState["PrevDate"].ToString().Trim() != "" &&
ViewState["CurrDate"] != null &&
ViewState["CurrDate"].ToString().Trim() != "")
{
if (DateTime.Parse(ViewState["PrevDate"].ToString()) >
DateTime.Parse("01-JAN-12") &&
DateTime.Parse(ViewState["CurrDate"].ToString()) >
DateTime.Parse("01-JAN-12"))
{
return "SELECT Statement to get CurrDate;
}
return "SELECT Statement to get PrevDate;
}
if (DateTime.Parse(ViewState["CurrDate"].ToString()) >
DateTime.Parse("01-JAN-12"))
{
return "SELECT Statement to get CurrDate (Same as the CurrDate above);
}
return "SELECT Statement to get PrevDate (Same as the PrevDate above);
}
From what you have done in the second block of code this is was what i could change, not much but what i have done is removed the else statements as you are returning i the first if statement, the else isn't needed.
Your friend: Case statements https://msdn.microsoft.com/en-GB/library/06tc147t.aspx
Multiple if statements also have a habit of slowing your code down because the IDE has to process all the conditions
With Case statements, it will only use certain pieces of information based on conditions
You can simplify this considerably by writing a method to parse a string into a nullable date:
private static DateTime? parseDate(object date)
{
DateTime result;
if (DateTime.TryParse(date.ToString(), out result))
return result;
return null;
}
Note that I had to make the parameter an object because I don't know what type ViewState["key"] returns.
One you have that you can simplify your code. However, doing so reveals that you haven't handled the case where currDate is not a valid date:
private string CheckBoxDescription()
{
var prevDate = parseDate(ViewState["PrevDate"]);
var currDate = parseDate(ViewState["CurrDate"]);
if (prevDate != null && currDate != null)
{
return
prevDate > DateTime.Parse("01-JAN-12") && currDate > DateTime.Parse("01-JAN-12")
? "SELECT Statement to get CurrDate"
: "SELECT Statement to get PrevDate";
}
// You have a problem here. What if currDate is not a valid date?
if (currDate == null)
throw new InvalidOperationException("Your current code doesn't handle this case.");
if (currDate > DateTime.Parse("01-JAN-12"))
{
return "SELECT Statement to get CurrDate (Same as the CurrDate above)";
}
else
{
return "SELECT Statement to get PrevDate (Same as the PrevDate above)";
}
}
How about this;
private string CheckBoxDescription()
{
var prevDate = ViewState["PrevDate"] != null && ViewState["PrevDate"].ToString().Trim() != ""
? DateTime.Parse(ViewState["PrevDate"].ToString())
: null;
var currDate = ViewState["PrevDate"] != null && ViewState["CurrDate"].ToString().Trim() != ""
? DateTime.Parse(ViewState["CurrDate"].ToString())
: null;
if (prevDate != null && currDate != null)
{
return
prevDate > DateTime.Parse("01-JAN-12") && currDate > DateTime.Parse("01-JAN-12")
? "SELECT Statement to get CurrDate"
: "SELECT Statement to get PrevDate";
}
if (currDate > DateTime.Parse("01-JAN-12"))
{
return "SELECT Statement to get CurrDate (Same as the CurrDate above);
}
else
{
return "SELECT Statement to get PrevDate (Same as the PrevDate above);
}
}

Checking if something is empty

I am currently checking if comboboxes and numericupdowns are empty but i am doing it with If statement.
Can you tell me if there is any other faster way of doing it?
Here is current code
private void button1_Click(object sender, EventArgs e)
{
if(comboBox1.SelectedItem != null)
{
if(comboBox2.SelectedItem != null)
{
if(numericUpDown1.Value != 0)
{
if(numericUpDown2.Value != 0)
{
if(numericUpDown3.Value != 0)
{
if(numericUpDown4.Value != 0)
{
string domacin = "" + comboBox1.GetItemText(comboBox1.SelectedItem);
int D_kosevaPrvoPoluvreme = (int)numericUpDown1.Value;
int D_kosevaDrugoPoluvreme = (int)numericUpDown3.Value;
int D_ukupnoKoseva = D_kosevaDrugoPoluvreme + D_kosevaPrvoPoluvreme;
int D_primljenihKosevaPrvoPoluvreme = (int)numericUpDown2.Value;
int D_primljenihKosevaDrugoPoluvreme = (int)numericUpDown4.Value;
int D_ukupnoPrimljenihKoseva = D_primljenihKosevaDrugoPoluvreme + D_primljenihKosevaPrvoPoluvreme;
string gost = "" + comboBox2.GetItemText(comboBox2.SelectedItem);
int G_kosevaPrvoPoluvreme = (int)numericUpDown2.Value;
int G_kosevaDrugoPoluvreme = (int)numericUpDown4.Value;
int G_ukupnoKoseva = G_kosevaDrugoPoluvreme + G_kosevaPrvoPoluvreme;
int G_primljenihKosevaPrvoPoluvreme = (int)numericUpDown1.Value;
int G_primljenihKosevaDrugoPoluvreme = (int)numericUpDown3.Value;
int G_ukupnoPrimljenihKoseva = G_primljenihKosevaDrugoPoluvreme + G_primljenihKosevaPrvoPoluvreme;
int rezultat;
Functions.odrediPobednika(out rezultat, D_ukupnoKoseva, G_ukupnoKoseva);
//SqlConnection con = new SqlConnection(#"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\arist\Documents\VisualStudio2015\Projects\NBA\NBA\NBA.mdf;Integrated Security=True");
//SqlCommand cmd = new SqlCommand("", con);
}
}
}
}
}
}
}
I would use following fail-fast-validation approach with meaningful messages:
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedItem == null)
{
MessageBox.Show("Meaningful message, user should know what he has done wrong", "Invalid xyz");
return;
}
else if (comboBox2.SelectedItem == null)
{
MessageBox.Show("Meaningful message, user should know what he has done wrong", "Invalid xyz");
return;
}
else if (numericUpDown1.Value == 0)
{
MessageBox.Show("Meaningful message, user should know what he has done wrong", "Invalid xyz");
return;
}
else if (numericUpDown2.Value == 0)
{
MessageBox.Show("Meaningful message, user should know what he has done wrong", "Invalid xyz");
return;
}
else if (numericUpDown3.Value == 0)
{
MessageBox.Show("Meaningful message, user should know what he has done wrong", "Invalid xyz");
return;
}
// insert code
}
It's neither shorter nor more efficient, but it's easy to read, to debug and most important: the user knows what went wrong. You should also use meaningful control-names.
Of course you could also use one if and concat all conditions with &&, but i'd prefer my first approach for the reasons mentioned above.
bool valid = comboBox1.SelectedItem != null
&& comboBox2.SelectedItem != null
&& numericUpDown1.Value != 0
&& numericUpDown2.Value != 0
&& numericUpDown3.Value != 0
&& numericUpDown4.Value != 0;
if(valid){
//Code
}
The first thing that springs to mind is to use one if statement
if(comboBox1.SelectedItem != null && comboBox2.SelectedItem != null && numericUpDown1.Value != 0 && numericUpDown2.Value != 0 && numericUpDown3.Value != 0 && numericUpDown4.Value != 0)
{
//Code
}
This can also be put onto multiple lines for readability
if(comboBox1.SelectedItem != null &&
comboBox2.SelectedItem != null &&
numericUpDown1.Value != 0 &&
numericUpDown2.Value != 0 &&
numericUpDown3.Value != 0 &&
numericUpDown4.Value != 0)
{
//Code
}
There's not much to optimize there in reference to execution times etc. But the code could be made a bit neater, a start could be something like:
private void button1_Click(object sender, EventArgs e)
{
if(comboBox1.SelectedItem != null &&
comboBox2.SelectedItem != null &&
numericUpDown1.Value != 0 &&
numericUpDown2.Value != 0 &&
numericUpDown3.Value != 0 &&
numericUpDown4.Value != 0)
{
string domacin = comboBox1.GetItemText(comboBox1.SelectedItem);
int D_kosevaPrvoPoluvreme = (int)numericUpDown1.Value;
int D_kosevaDrugoPoluvreme = (int)numericUpDown3.Value;
int D_ukupnoKoseva = D_kosevaDrugoPoluvreme + D_kosevaPrvoPoluvreme;
int D_primljenihKosevaPrvoPoluvreme = (int)numericUpDown2.Value;
int D_primljenihKosevaDrugoPoluvreme = (int)numericUpDown4.Value;
int D_ukupnoPrimljenihKoseva = D_primljenihKosevaDrugoPoluvreme + D_primljenihKosevaPrvoPoluvreme;
string gost = comboBox2.GetItemText(comboBox2.SelectedItem);
int G_kosevaPrvoPoluvreme = (int)numericUpDown2.Value;
int G_kosevaDrugoPoluvreme = (int)numericUpDown4.Value;
int G_ukupnoKoseva = G_kosevaDrugoPoluvreme + G_kosevaPrvoPoluvreme;
int G_primljenihKosevaPrvoPoluvreme = (int)numericUpDown1.Value;
int G_primljenihKosevaDrugoPoluvreme = (int)numericUpDown3.Value;
int G_ukupnoPrimljenihKoseva = G_primljenihKosevaDrugoPoluvreme + G_primljenihKosevaPrvoPoluvreme;
int rezultat;
Functions.odrediPobednika(out rezultat, D_ukupnoKoseva, G_ukupnoKoseva);
//SqlConnection con = new SqlConnection(#"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\arist\Documents\VisualStudio2015\Projects\NBA\NBA\NBA.mdf;Integrated Security=True");
//SqlCommand cmd = new SqlCommand("", con);
}
}

Why is this dynamic list comparison failing?

I have a search that returns a result that is dynamic. So I am trying to just show a label if there are no results found. The problem i am having is i dont know how to count the result because it is dynamic and is not equal to a type.
The error message is :
Operator '!=' Cannot be applied ot operands of type
System.Collections.Generic.List and int
if (Page.IsValid)
{
string keyword = txtSearch.Text.Trim();
List<dynamic> results = SearchItems(keyword);
List<dynamic> Cresults = SearchContacts(keyword);
if(results != 0 || Cresults !=0)
{
//bind and return
LVI.DataSource = results;
LVI.DataBind();
// System.Threading.Thread.Sleep(500);
//Contact Bind return
LVC.DataSource = Cresults;
LVC.DataBind();
// System.Threading.Thread.Sleep(250);
lvAdmin.DataSource = results;
lvAdmin.DataBind();
LVCAdmin.DataSource = Cresults;
LVCAdmin.DataBind();
}
else{
NoResults.Visible = true;
}
You cannot just do:
if(results != 0 || Cresults !=0)
{
}
That way your comparing the actual List to 0, which obviously fails.
Just do:
if(results.Count != 0 || Cresults.Count !=0)
{
}
Or:
if(results.Any() || Cresults.Any())
{
}
Use the Count property of the List class:
if (results.Count != 0 || Cresults.Count != 0)
{
//rest of code
}
Docs: http://msdn.microsoft.com/en-us/library/a7f69ad7.aspx
you can try using count
if(results.Count > 0 || Cresults.Count > 0)

Workflow for Collection.Add()

DataTable.Rows.Add() adds a row to the data table. However, how does it handle the underlying array?
When adding a single row at a time, does it rebuild the entire array with each row added?
Or is it able to simply modify the existing array without any hit on performance?
I am wondering if it’s better to determine the size of the array before filling it with data, or if somehow the data table is able to modify the collection without (behind the scenes) copying and moving things.
It’s my understanding that to adjust an array you have to redefine it and move previously existing data into the new structure.
My question is what is the work flow for the Collection.Add() method?
Take a look using software like DotPeek:
DataTable.Rows.Add(DataRow row)
{
this.table.AddRow(row, -1);
}
which calls:
DataTable.AddRow(DataRow row, int proposedID)
{
this.InsertRow(row, proposedID, -1);
}
which calls:
DataTable.InsertRow(DataRow row, int proposedID, int pos)
{
this.InsertRow(row, (long) proposedID, pos, true);
}
which calls:
DataTable.InsertRow(DataRow row, long proposedID, int pos, bool fireEvent)
{
Exception deferredException = (Exception) null;
if (row == null)
throw ExceptionBuilder.ArgumentNull("row");
if (row.Table != this)
throw ExceptionBuilder.RowAlreadyInOtherCollection();
if (row.rowID != -1L)
throw ExceptionBuilder.RowAlreadyInTheCollection();
row.BeginEdit();
int proposedRecord = row.tempRecord;
row.tempRecord = -1;
if (proposedID == -1L)
proposedID = this.nextRowID;
bool flag;
if (flag = this.nextRowID <= proposedID)
this.nextRowID = checked (proposedID + 1L);
try
{
try
{
row.rowID = proposedID;
this.SetNewRecordWorker(row, proposedRecord, DataRowAction.Add, false, false, pos, fireEvent, out deferredException);
}
catch
{
if (flag && this.nextRowID == proposedID + 1L)
this.nextRowID = proposedID;
row.rowID = -1L;
row.tempRecord = proposedRecord;
throw;
}
if (deferredException != null)
throw deferredException;
if (!this.EnforceConstraints || this.inLoad)
return;
int count = this.columnCollection.Count;
for (int index = 0; index < count; ++index)
{
DataColumn dataColumn = this.columnCollection[index];
if (dataColumn.Computed)
dataColumn.CheckColumnConstraint(row, DataRowAction.Add);
}
}
finally
{
row.ResetLastChangedColumn();
}
}
which calls:
DataTable.SetNewRecordWorker(DataRow row, int proposedRecord, DataRowAction action, bool isInMerge, bool suppressEnsurePropertyChanged, int position, bool fireEvent, out Exception deferredException)
{
deferredException = (Exception) null;
if (row.tempRecord != proposedRecord)
{
if (!this.inDataLoad)
{
row.CheckInTable();
this.CheckNotModifying(row);
}
if (proposedRecord == row.newRecord)
{
if (!isInMerge)
return;
this.RaiseRowChanged((DataRowChangeEventArgs) null, row, action);
return;
}
else
row.tempRecord = proposedRecord;
}
DataRowChangeEventArgs args = (DataRowChangeEventArgs) null;
try
{
row._action = action;
args = this.RaiseRowChanging((DataRowChangeEventArgs) null, row, action, fireEvent);
}
catch
{
row.tempRecord = -1;
throw;
}
finally
{
row._action = DataRowAction.Nothing;
}
row.tempRecord = -1;
int record = row.newRecord;
int num = proposedRecord != -1 ? proposedRecord : (row.RowState != DataRowState.Unchanged ? row.oldRecord : -1);
if (action == DataRowAction.Add)
{
if (position == -1)
this.Rows.ArrayAdd(row);
else
this.Rows.ArrayInsert(row, position);
}
List<DataRow> cachedRows = (List<DataRow>) null;
if ((action == DataRowAction.Delete || action == DataRowAction.Change) && (this.dependentColumns != null && this.dependentColumns.Count > 0))
{
cachedRows = new List<DataRow>();
for (int index = 0; index < this.ParentRelations.Count; ++index)
{
DataRelation relation = this.ParentRelations[index];
if (relation.ChildTable == row.Table)
cachedRows.InsertRange(cachedRows.Count, (IEnumerable<DataRow>) row.GetParentRows(relation));
}
for (int index = 0; index < this.ChildRelations.Count; ++index)
{
DataRelation relation = this.ChildRelations[index];
if (relation.ParentTable == row.Table)
cachedRows.InsertRange(cachedRows.Count, (IEnumerable<DataRow>) row.GetChildRows(relation));
}
}
if (!suppressEnsurePropertyChanged && !row.HasPropertyChanged && (row.newRecord != proposedRecord && -1 != proposedRecord) && -1 != row.newRecord)
{
row.LastChangedColumn = (DataColumn) null;
row.LastChangedColumn = (DataColumn) null;
}
if (this.LiveIndexes.Count != 0)
{
if (-1 == record && -1 != proposedRecord && (-1 != row.oldRecord && proposedRecord != row.oldRecord))
record = row.oldRecord;
DataViewRowState recordState1 = row.GetRecordState(record);
DataViewRowState recordState2 = row.GetRecordState(num);
row.newRecord = proposedRecord;
if (proposedRecord != -1)
this.recordManager[proposedRecord] = row;
DataViewRowState recordState3 = row.GetRecordState(record);
DataViewRowState recordState4 = row.GetRecordState(num);
this.RecordStateChanged(record, recordState1, recordState3, num, recordState2, recordState4);
}
else
{
row.newRecord = proposedRecord;
if (proposedRecord != -1)
this.recordManager[proposedRecord] = row;
}
row.ResetLastChangedColumn();
if (-1 != record && record != row.oldRecord && (record != row.tempRecord && record != row.newRecord) && row == this.recordManager[record])
this.FreeRecord(ref record);
if (row.RowState == DataRowState.Detached && row.rowID != -1L)
this.RemoveRow(row, false);
if (this.dependentColumns != null)
{
if (this.dependentColumns.Count > 0)
{
try
{
this.EvaluateExpressions(row, action, cachedRows);
}
catch (Exception ex)
{
if (action != DataRowAction.Add)
throw ex;
deferredException = ex;
}
}
}
try
{
if (!fireEvent)
return;
this.RaiseRowChanged(args, row, action);
}
catch (Exception ex)
{
if (!ADP.IsCatchableExceptionType(ex))
throw;
else
ExceptionBuilder.TraceExceptionWithoutRethrow(ex);
}
}
which calls one of those:
DataRowCollection.ArrayAdd(DataRow row)
{
row.RBTreeNodeId = this.list.Add(row);
}
DataRowCollection.ArrayInsert(DataRow row, int pos)
{
row.RBTreeNodeId = this.list.Insert(pos, row);
}
this.list is of type DataRowCollection.DataRowTree, derived from RBTree<DataRow>.
private sealed class DataRowTree : RBTree<DataRow>
RBTree<DataRow> and RBTreeNodeId allows us to conclude that a Red-Black tree is being used!

Categories

Resources