积极答复者
LoadDataRow和Select

问题
答案
-
看源代码:
1)DataTable's LoadDataRow:同时查询数据,并且统一修改行状态为Unchanged。
public DataRow LoadDataRow(object[] values, bool fAcceptChanges) { DataRow item; DataRow dataRow; IntPtr intPtr; Bid.ScopeEnter(out intPtr, "<ds.DataTable.LoadDataRow|API> %d#, fAcceptChanges=%d{bool}\n", this.ObjectID, fAcceptChanges); try { if (!this.inDataLoad) { item = this.UpdatingAdd(values); if (fAcceptChanges) { item.AcceptChanges(); } dataRow = item; } else { int num = this.NewRecordFromArray(values); if (this.loadIndex != null) { int num1 = this.loadIndex.FindRecord(num); if (num1 != -1) { int record = this.loadIndex.GetRecord(num1); item = this.recordManager[record]; item.CancelEdit(); if (item.RowState == DataRowState.Deleted) { this.SetNewRecord(item, item.oldRecord, DataRowAction.Rollback, false, true, false); } this.SetNewRecord(item, num, DataRowAction.Change, false, true, false); if (fAcceptChanges) { item.AcceptChanges(); } dataRow = item; return dataRow; } } item = this.NewRow(num); this.AddRow(item); if (fAcceptChanges) { item.AcceptChanges(); } dataRow = item; } } finally { Bid.ScopeLeave(ref intPtr); } return dataRow; }
2) DataTable's Select:不修改行状态,仅仅为获取数据。
public DataRow[] SelectRows() { Range range; bool flag = true; this.InitCandidateColumns(); if (!(this.expression is BinaryNode)) { this.linearExpression = this.expression; } else { this.AnalyzeExpression((BinaryNode)this.expression); if (!this.candidatesForBinarySearch) { this.linearExpression = this.expression; } if (this.linearExpression != this.expression) { flag = !this.FindClosestCandidateIndex(); } else { for (int i = 0; i < (int)this.candidateColumns.Length; i++) { if (this.candidateColumns[i] != null) { this.candidateColumns[i].equalsOperator = false; this.candidateColumns[i].expr = null; } } } } if (this.index == null && ((int)this.IndexFields.Length > 0 || this.linearExpression == this.expression)) { flag = !this.FindSortIndex(); } if (this.index == null) { this.CreateIndex(); flag = false; } if (this.index.RecordCount == 0) { return this.table.NewRowArray(0); } if (this.matchedCandidates == 0) { range = new Range(0, this.index.RecordCount - 1); this.linearExpression = this.expression; return this.GetLinearFilteredRows(range); } range = this.GetBinaryFilteredRecords(); if (range.Count == 0) { return this.table.NewRowArray(0); } if (this.matchedCandidates < this.nCandidates) { this.BuildLinearExpression(); } if (!flag) { return this.GetLinearFilteredRows(range); } this.records = this.GetLinearFilteredRecords(range); this.recordCount = (int)this.records.Length; if (this.recordCount == 0) { return this.table.NewRowArray(0); } this.Sort(0, this.recordCount - 1); return this.GetRows(); }
要获取数据,还可以用DataView中的RowFilter属性设置条件过滤,您可以参考:
http://msdn.microsoft.com/zh-cn/library/system.data.dataview.rowfilter.aspx
Click For donating:Free Rice For the poor
For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
For more things to talk about? StackOverFlow is your choice.- 已标记为答案 CaillenModerator 2013年10月21日 6:19