system.data.datatable

Get difference between two data-tables according to one column

寵の児 提交于 2019-12-10 11:09:11
问题 I have the following scenario: Table A that has 50 records and Table B that has 2 records. I need to define a new table, say TableDiff which should contain 48 records from Table A that doesn't exist in Table B My problem is that Table A and Table B are not identical but I have the field rowId which exists in both tables that I need to compare using it. 回答1: One way using Enumerable.Except and Enumerable.Join : var aIDs = TableA.AsEnumerable().Select(r => r.Field<int>("RowID")); var bIDs =

Get difference between two data-tables according to one column

雨燕双飞 提交于 2019-12-06 05:19:55
I have the following scenario: Table A that has 50 records and Table B that has 2 records. I need to define a new table, say TableDiff which should contain 48 records from Table A that doesn't exist in Table B My problem is that Table A and Table B are not identical but I have the field rowId which exists in both tables that I need to compare using it. One way using Enumerable.Except and Enumerable.Join : var aIDs = TableA.AsEnumerable().Select(r => r.Field<int>("RowID")); var bIDs = TableB.AsEnumerable().Select(r => r.Field<int>("RowID")); var diff = aIDs.Except(bIDs); DataTable tblDiff =

Datatable.Dispose() will make it remove from memory?

不羁的心 提交于 2019-11-28 01:07:15
I have researching through very simple code and get stuck on seeing the dispose() result of datatable Following is the code DataTable dt= new Datatable(); SqlCommand Cmd = new SqlCommand("sp_getData",SqlCon); SqlCommand.CommandType= CommandType.StroedProcedure; SqlCon.Open(); sqlDataReader dr= cmd.ExecuteReader(); dt.Load(dr); SqlCon.Close(); grdView.DataSource =dt; dt.Dispose() // Here I dispose the table as it is no use for me & wanna memory free from this But after disposing off the datatable i still found that it is still showing RowCount = 10k. Does Dispose() method does not free up the

Datatable.Dispose() will make it remove from memory?

故事扮演 提交于 2019-11-26 21:49:14
问题 I have researching through very simple code and get stuck on seeing the dispose() result of datatable Following is the code DataTable dt= new Datatable(); SqlCommand Cmd = new SqlCommand("sp_getData",SqlCon); SqlCommand.CommandType= CommandType.StroedProcedure; SqlCon.Open(); sqlDataReader dr= cmd.ExecuteReader(); dt.Load(dr); SqlCon.Close(); grdView.DataSource =dt; dt.Dispose() // Here I dispose the table as it is no use for me & wanna memory free from this But after disposing off the

Compare two DataTables and select the rows that are not present in second table

痞子三分冷 提交于 2019-11-26 18:24:15
问题 I have two DataTables and I want to select the rows from the first one which are not present in second one For example: Table A id column 1 data1 2 data2 3 data3 4 data4 Table B id column 1 data10 3 data30 I want the result to be: Table C id column 2 data2 4 data4 回答1: You can use Linq, especially Enumerable.Except helps to find id's in TableA that are not in TableB: var idsNotInB = TableA.AsEnumerable().Select(r => r.Field<int>("id")) .Except(TableB.AsEnumerable().Select(r => r.Field<int>(