In this tutorial, I’ll show you how to copy specific columns
from one datatable to another datatable in c#
.
Suppose, I have a complex store procedure in my SQL Database, which returns 25 columns with a large amount of data. I use the store procedure in multiple forms so that I can’t change the store procedure. I want to copy specific columns from the DataTable to another in C#. I follow the method and it’s working fine.
1 2 3 4 5 6 7 8 9 10 11 | public DataTable LoadMyData(Hashtable ht) { _dbTable = new DataTable(); _reader = new DataReader(); DataTable _dt = _reader.GetDataTableByCommandFromStoredProc("SP_ATTENDANCE", ht); //get datatable by execute store procedure String[] columnList = new String[] { "AttnDate", "Status", "ActualInTime", "ActualOutTime", "OutStatus" }; //list of my specific columns return _dbTable = new DataView(_dt).ToTable(false, columnList); } |
Copy specific columns from one DataTable to another
The article was published on November 17, 2018 @ 12:28 PM
Leave a Comment