Sometimes we have to create generic dictionary from the values in datatable. Usually we will loop through all the rows in the datatable and add the relevant keys to dictionary object for ( int _iExRowCnt = 0; _iExRowCnt < dsReturn.Tables[0].Rows.Count; _iExRowCnt++) { //add some code to chek null values & other validations if any _dictObj.Add(dsReturn.Tables[0].Rows[iExRowCnt][0].dsReturn.Tables[0].Rows[iExRowCnt][1]); } After LINQ was introduced there better way of doing the same addition. In the following code i am creating a datatable and populaing few dummy records. DataTable dtTable = new DataTable (); dtTable.Columns.Add( new DataColumn ( "ColumnNo" , typeof (System. String ))); dtTable.Columns.Add( new DataColumn ( "controlType" , typeof (System. String ))); dtTable.Columns.Add( new DataColumn ( "showVal" , typeof (System. Boolean ))); DataRow dr; for ( int i = 0; i < 10; i++) { dr = dtTable.NewRow(); dr[0]
The practical "bytes" of Agile And DevOps Transformation