/Tools/clsDataTable.cs

http://inferno4proteomics.googlecode.com/ · C# · 741 lines · 617 code · 52 blank · 72 comment · 70 complexity · a44fd3091c3bafac863c39d86e9ae5cd MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.Text;
  5. using System.Data;
  6. using System.Data.OleDb;
  7. using System.IO;
  8. using System.Windows.Forms;
  9. using LumenWorks.Framework.IO.Csv;
  10. using DAnTE.Tools;
  11. namespace DAnTE.Tools
  12. {
  13. public static class clsDataTable
  14. {
  15. #region File loading methods
  16. public static DataTable LoadFile2DataTable(string FileName)
  17. {
  18. string fileName = FileName;
  19. string filePath = FileName;
  20. string fExt;
  21. String sConnectionString = "";
  22. DataTable mdtOut = new DataTable();
  23. DataTable mdtIn = new DataTable();
  24. fileName = Path.GetFileName(FileName);
  25. filePath = Path.GetDirectoryName(FileName);
  26. fExt = Path.GetExtension(fileName);
  27. switch (fExt)
  28. {
  29. case ".csv":// CSV files
  30. using (clsGenericParserAdapter parser = new clsGenericParserAdapter())
  31. {
  32. parser.SetDataSource(FileName);
  33. parser.ColumnDelimiter = ",".ToCharArray();
  34. parser.FirstRowHasHeader = true;
  35. parser.MaxBufferSize = 4096;
  36. parser.TextQualifier = '\"';
  37. mdtIn = parser.GetDataTable();
  38. parser.Close();
  39. mdtOut = clsDataTable.ReplaceMissingStr(mdtIn);
  40. }
  41. break;
  42. case ".txt":
  43. using (clsGenericParserAdapter parser = new clsGenericParserAdapter())
  44. {
  45. parser.SetDataSource(FileName);
  46. parser.ColumnDelimiter = "\t".ToCharArray();
  47. parser.FirstRowHasHeader = true;
  48. parser.MaxBufferSize = 4096;
  49. parser.TextQualifier = '\"';
  50. mdtIn = parser.GetDataTable();
  51. parser.Close();
  52. mdtOut = clsDataTable.ReplaceMissingStr(mdtIn);
  53. }
  54. break;
  55. case ".xls"://Excel files
  56. sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
  57. FileName + ";" + "Extended Properties=Excel 8.0;";
  58. goto case "Excel";
  59. case ".xlsx": // New Excel files
  60. sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" +
  61. FileName + ";" + "Extended Properties=Excel 12.0;";
  62. goto case "Excel";
  63. case "Excel":
  64. OleDbConnection objConn = null;
  65. DataTable dt = null;
  66. try
  67. {
  68. //String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
  69. // FileName + ";" + "Extended Properties=Excel 8.0;";
  70. objConn = new OleDbConnection(sConnectionString);
  71. objConn.Open();
  72. dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  73. if (dt == null)
  74. {
  75. return null;
  76. }
  77. String[] excelSheets = new String[dt.Rows.Count];
  78. int i = 0;
  79. // Add the sheet name to the string array.
  80. foreach (DataRow row in dt.Rows)
  81. {
  82. excelSheets[i] = row["TABLE_NAME"].ToString();
  83. i++;
  84. }
  85. string sheetCmd = "SELECT * FROM [" + excelSheets[0] +"]"; //read the first table
  86. OleDbCommand objCmdSelect = new OleDbCommand(sheetCmd, objConn);
  87. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
  88. objAdapter1.SelectCommand = objCmdSelect;
  89. objAdapter1.Fill(mdtOut);
  90. //mdtOut = clsDataTable.ClearNulls(mdtIn) ;
  91. }
  92. catch (Exception ex)
  93. {
  94. Console.WriteLine(ex.Message.ToString());
  95. }
  96. finally
  97. {
  98. // Clean up.
  99. if (objConn != null)
  100. {
  101. objConn.Close();
  102. objConn.Dispose();
  103. }
  104. if (dt != null)
  105. {
  106. dt.Dispose();
  107. }
  108. }
  109. break;
  110. default:
  111. Console.WriteLine("Unknown File");
  112. //fileOK = false;
  113. mdtOut = null;
  114. break;
  115. }
  116. return mdtOut;
  117. }
  118. public static DataTable LoadFile2DataTableJETOLEDB(string FileName)
  119. {
  120. string fileName = FileName;
  121. string filePath = FileName;
  122. string fExt;
  123. DataTable mdtOut = new DataTable();
  124. DataTable mdtIn = new DataTable();
  125. OleDbConnection objConn = null;
  126. DataTable dt = null;
  127. fileName = Path.GetFileName(FileName);
  128. filePath = Path.GetDirectoryName(FileName);
  129. fExt = Path.GetExtension(fileName);
  130. switch (fExt)
  131. {
  132. case ".csv":// CSV files
  133. case ".txt":
  134. objConn = null;
  135. dt = null;
  136. try
  137. {
  138. String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  139. "Data Source=" + filePath + ";" +
  140. @"Extended Properties=""text;HDR=Yes;FMT=Delimited""";
  141. objConn = new OleDbConnection(sConnectionString);
  142. objConn.Open();
  143. string sheetCmd = "SELECT * FROM [" + fileName + "]"; //read the table
  144. OleDbCommand objCmdSelect = new OleDbCommand(sheetCmd, objConn);
  145. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
  146. objAdapter1.SelectCommand = objCmdSelect;
  147. objAdapter1.Fill(mdtOut);
  148. //mdtOut = clsDataTable.ClearNulls(mdtIn) ;
  149. }
  150. catch (Exception ex)
  151. {
  152. Console.WriteLine(ex.Message.ToString());
  153. }
  154. finally
  155. {
  156. // Clean up.
  157. if (objConn != null)
  158. {
  159. objConn.Close();
  160. objConn.Dispose();
  161. }
  162. if (dt != null)
  163. {
  164. dt.Dispose();
  165. }
  166. }
  167. break;
  168. case ".xls"://Excel files
  169. objConn = null;
  170. dt = null;
  171. try
  172. {
  173. String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
  174. FileName + ";" + "Extended Properties=Excel 8.0;";
  175. objConn = new OleDbConnection(sConnectionString);
  176. objConn.Open();
  177. dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  178. if (dt == null)
  179. {
  180. return null;
  181. }
  182. String[] excelSheets = new String[dt.Rows.Count];
  183. int i = 0;
  184. // Add the sheet name to the string array.
  185. foreach (DataRow row in dt.Rows)
  186. {
  187. excelSheets[i] = row["TABLE_NAME"].ToString();
  188. i++;
  189. }
  190. string sheetCmd = "SELECT * FROM [" + excelSheets[0] + "]"; //read the first table
  191. OleDbCommand objCmdSelect = new OleDbCommand(sheetCmd, objConn);
  192. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
  193. objAdapter1.SelectCommand = objCmdSelect;
  194. objAdapter1.Fill(mdtOut);
  195. //mdtOut = clsDataTable.ClearNulls(mdtIn) ;
  196. }
  197. catch (Exception ex)
  198. {
  199. Console.WriteLine(ex.Message.ToString());
  200. }
  201. finally
  202. {
  203. // Clean up.
  204. if (objConn != null)
  205. {
  206. objConn.Close();
  207. objConn.Dispose();
  208. }
  209. if (dt != null)
  210. {
  211. dt.Dispose();
  212. }
  213. }
  214. break;
  215. default:
  216. Console.WriteLine("Unknown File");
  217. //fileOK = false;
  218. mdtOut = null;
  219. break;
  220. }
  221. return mdtOut;
  222. }
  223. public static DataTable LoadFile2DataTableFastCSVReader(string FileName)
  224. {
  225. string fileName = FileName;
  226. string filePath = FileName;
  227. string fExt;
  228. String sConnectionString = "";
  229. DataTable mdtOut = new DataTable();
  230. DataTable mdtIn = new DataTable();
  231. fileName = Path.GetFileName(FileName);
  232. filePath = Path.GetDirectoryName(FileName);
  233. fExt = Path.GetExtension(fileName);
  234. switch (fExt)
  235. {
  236. case ".csv":// CSV files
  237. using (CsvReader csv = new CsvReader(new System.IO.StreamReader(FileName), true))
  238. {
  239. csv.MissingFieldAction = MissingFieldAction.ReplaceByEmpty;
  240. mdtOut.Load(csv);
  241. }
  242. break;
  243. case ".txt":
  244. using (CsvReader csv = new CsvReader(new System.IO.StreamReader(FileName), true, '\t'))
  245. {
  246. csv.MissingFieldAction = MissingFieldAction.ReplaceByEmpty;
  247. mdtOut.Load(csv);
  248. }
  249. break;
  250. case ".xls"://Excel files
  251. sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
  252. FileName + ";" + "Extended Properties=Excel 8.0;";
  253. goto case "Excel";
  254. case ".xlsx": // New Excel files
  255. sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" +
  256. FileName + ";" + "Extended Properties=Excel 12.0;";
  257. goto case "Excel";
  258. case "Excel":
  259. OleDbConnection objConn = null;
  260. DataTable dt = null;
  261. string mstrSheet = null;
  262. try
  263. {
  264. //String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
  265. // FileName + ";" + @"Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;""";
  266. objConn = new OleDbConnection(sConnectionString);
  267. objConn.Open();
  268. dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  269. if (dt == null)
  270. {
  271. return null;
  272. }
  273. if (dt.Rows.Count == 1)
  274. mstrSheet = (dt.Rows[0])["TABLE_NAME"].ToString();
  275. else
  276. {
  277. ArrayList marrExcelSheets = new ArrayList();
  278. int i = 0;
  279. // Add the sheet name to the string array.
  280. foreach (DataRow row in dt.Rows)
  281. {
  282. mstrSheet = row["TABLE_NAME"].ToString();
  283. marrExcelSheets.Add(mstrSheet);
  284. i++;
  285. }
  286. frmSelectExcelSheet mfrmSheets = new frmSelectExcelSheet();
  287. mfrmSheets.PopulateListBox = marrExcelSheets;
  288. if (mfrmSheets.ShowDialog() == DialogResult.OK)
  289. {
  290. i = mfrmSheets.SelectedSheet;
  291. mstrSheet = marrExcelSheets[i].ToString();
  292. }
  293. else
  294. {
  295. mdtOut = null;
  296. break;
  297. }
  298. }
  299. string sheetCmd = "SELECT * FROM [" + mstrSheet + "]";
  300. OleDbCommand objCmdSelect = new OleDbCommand(sheetCmd, objConn);
  301. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
  302. objAdapter1.SelectCommand = objCmdSelect;
  303. objAdapter1.Fill(mdtOut);
  304. }
  305. catch (Exception ex)
  306. {
  307. Console.WriteLine(ex.Message.ToString());
  308. }
  309. finally
  310. {
  311. // Clean up.
  312. if (objConn != null)
  313. {
  314. objConn.Close();
  315. objConn.Dispose();
  316. }
  317. if (dt != null)
  318. {
  319. dt.Dispose();
  320. }
  321. }
  322. break;
  323. default:
  324. Console.WriteLine("Unknown File");
  325. //fileOK = false;
  326. mdtOut = null;
  327. break;
  328. }
  329. return mdtOut;
  330. }
  331. #endregion
  332. public static DataTable Array2DataTable(double[,] matrix, string[] rowNames, string[] colHeaders)
  333. {
  334. DataTable mDataTable = new DataTable();
  335. DataColumn mDataColumn;
  336. DataRow mDataRow;
  337. mDataColumn = new DataColumn();
  338. mDataColumn.DataType = System.Type.GetType("System.String");
  339. mDataColumn.ColumnName = "Row_ID";
  340. //mDataColumn.ReadOnly = true ;
  341. mDataTable.Columns.Add(mDataColumn);
  342. for (int i = 0; i < colHeaders.Length; i++)
  343. {
  344. mDataColumn = new DataColumn();
  345. mDataColumn.DataType = System.Type.GetType("System.String");
  346. mDataColumn.ColumnName = colHeaders[i];
  347. //mDataColumn.ReadOnly = true ;
  348. mDataTable.Columns.Add(mDataColumn);
  349. }
  350. for (int i = 0; i < matrix.GetLength(0); i++)
  351. {
  352. mDataRow = mDataTable.NewRow();
  353. mDataRow[0] = rowNames[i];
  354. for (int j = 0; j < matrix.GetLength(1); j++)
  355. {
  356. mDataRow[j + 1] = matrix[i, j].ToString();
  357. }
  358. mDataTable.Rows.Add(mDataRow);
  359. }
  360. return ReplaceMissingStr(mDataTable);
  361. }
  362. public static string[] DataColumn2strArray(DataTable mTab, string Colmn)
  363. {
  364. string[] mStrArr = new string[mTab.Rows.Count];
  365. DataColumnCollection columns = mTab.Columns;
  366. int i = 0;
  367. foreach (DataColumn column in columns)
  368. {
  369. if (!Colmn.Equals(column.ColumnName))
  370. i++;
  371. else
  372. break;
  373. }
  374. for (int row = 0; row < mTab.Rows.Count; row++)
  375. {
  376. mStrArr[row] = mTab.Rows[row].ItemArray[i].ToString();
  377. }
  378. return mStrArr;
  379. }
  380. public static DataTable ReplaceMissingStr(DataTable dt)
  381. {
  382. string cell = null;
  383. int Nrows = dt.Rows.Count;
  384. //DataTable outDtable = new DataTable();
  385. for (int row = 0; row < Nrows; row++)
  386. {
  387. //DataRow workRow = dt.Rows[row] ;
  388. string[] obj;
  389. obj = new string[dt.Rows[row].ItemArray.Length];
  390. for (int col = 0; col < dt.Rows[row].ItemArray.Length; col++)
  391. {
  392. obj[col] = dt.Rows[row].ItemArray[col].ToString();
  393. cell = dt.Rows[row].ItemArray[col].ToString();
  394. if (cell.Equals("999999") || cell.Equals(" 9.999990e+05"))
  395. {
  396. string s = "";
  397. obj[col] = s;
  398. }
  399. }
  400. //outDtable.Rows.Add(obj);
  401. dt.Rows[row].ItemArray = obj;
  402. }
  403. dt.AcceptChanges();
  404. return dt;
  405. }
  406. public static DataTable ReplaceMissing(DataTable dt)
  407. {
  408. string cell = null;
  409. int Nrows = dt.Rows.Count;
  410. //DataTable outDtable = new DataTable();
  411. for (int row = 0; row < Nrows; row++)
  412. {
  413. //DataRow workRow = dt.Rows[row] ;
  414. Object[] obj = new object[dt.Rows[row].ItemArray.Length];
  415. //obj = new string[dt.Rows[row].ItemArray.Length];
  416. for (int col = 0; col < dt.Rows[row].ItemArray.Length; col++)
  417. {
  418. obj[col] = dt.Rows[row].ItemArray[col];
  419. cell = dt.Rows[row].ItemArray[col].ToString();
  420. if (cell.Equals("999999") || cell.Equals(" 9.999990e+05"))
  421. {
  422. obj[col] = System.DBNull.Value;
  423. }
  424. }
  425. //outDtable.Rows.Add(obj);
  426. dt.Rows[row].ItemArray = obj;
  427. }
  428. dt.AcceptChanges();
  429. return dt;
  430. }
  431. public static DataTable ClearNulls(DataTable dt)
  432. {
  433. int Nrows = dt.Rows.Count;
  434. DataTable outDtable = new DataTable();
  435. for (int row = 0; row < Nrows; row++)
  436. {
  437. //DataRow workRow = dt.Rows[row] ;
  438. object[] obj;
  439. obj = new object[dt.Rows[row].ItemArray.Length];
  440. for (int col = 0; col < dt.Rows[row].ItemArray.Length; col++)
  441. {
  442. obj[col] = dt.Rows[row].ItemArray[col];
  443. if (dt.Rows[row].ItemArray[col] == System.DBNull.Value)
  444. {
  445. string s = "";
  446. obj[col] = (object)s;
  447. }
  448. }
  449. dt.Rows[row].ItemArray = obj;
  450. }
  451. dt.AcceptChanges();
  452. return dt;
  453. }
  454. public static void RemoveDuplicateRows(DataTable dTable, string colName)
  455. {
  456. Hashtable hTable = new Hashtable();
  457. ArrayList duplicateList = new ArrayList();
  458. foreach (DataRow drow in dTable.Rows)
  459. {
  460. try
  461. {
  462. hTable.Add(drow[colName], string.Empty);
  463. }
  464. catch
  465. {
  466. duplicateList.Add(drow);
  467. }
  468. }
  469. foreach (DataRow dRow in duplicateList)
  470. dTable.Rows.Remove(dRow);
  471. }
  472. public static DataTable RemoveDuplicateRows2(DataTable dTable, string colName)
  473. {
  474. Hashtable hTable = new Hashtable();
  475. DataRow prevRow;
  476. ArrayList duplicateList = new ArrayList();
  477. foreach (DataColumn dC in dTable.Columns)
  478. {
  479. dC.ReadOnly = false;
  480. }
  481. foreach (DataRow thisRow in dTable.Rows)
  482. {
  483. if (!ValidRow(thisRow))
  484. duplicateList.Add(thisRow);
  485. else
  486. try
  487. {
  488. hTable.Add(thisRow[colName], thisRow);
  489. }
  490. catch
  491. {
  492. duplicateList.Add(thisRow);
  493. prevRow = (DataRow)hTable[thisRow[colName]];
  494. if (!RowsIdentical(thisRow, prevRow))
  495. {
  496. DataRow currentRow = addRows(prevRow, thisRow);
  497. hTable[thisRow[colName]] = currentRow;
  498. dTable.AcceptChanges();
  499. }
  500. }
  501. }
  502. foreach (DataRow dRow in duplicateList)
  503. dTable.Rows.Remove(dRow);
  504. return dTable;
  505. }
  506. public static bool RowsIdentical(DataRow row1, DataRow row2)
  507. {
  508. bool success = true;
  509. for (int i = 0; i < row1.ItemArray.Length; i++)
  510. {
  511. if (!(row1.ItemArray[i].Equals(row2.ItemArray[i])))
  512. {
  513. success = false;
  514. break;
  515. }
  516. }
  517. return success;
  518. }
  519. public static bool ValidRow(DataRow row) // not all empty
  520. {
  521. bool success = false;
  522. for (int i = 1; i < row.ItemArray.Length; i++)
  523. {
  524. if (!(row.ItemArray[i].Equals("")))
  525. {
  526. success = true;
  527. break;
  528. }
  529. }
  530. return success;
  531. }
  532. public static DataRow addRows(DataRow row1, DataRow row2)
  533. {
  534. Double val1, val2, val3;
  535. for (int i = 1; i < row1.ItemArray.Length; i++)
  536. {
  537. val1 = row1.ItemArray[i].Equals("") ? 0 : Convert.ToDouble(row1.ItemArray[i]);
  538. val2 = row2.ItemArray[i].Equals("") ? 0 : Convert.ToDouble(row2.ItemArray[i]);
  539. val3 = val1 + val2;
  540. if (Math.Abs(val3) > Double.Epsilon)
  541. row1[i] = val3.ToString();
  542. }
  543. return row1;
  544. }
  545. //----------------------------------------------------------------------------
  546. /// <summary>
  547. /// Removes duplicate rows from given DataTable
  548. /// </summary>
  549. /// <param name="tbl">Table to scan for duplicate rows</param>
  550. /// <param name="KeyColumns">An array of DataColumns
  551. /// containing the columns to match for duplicates</param>
  552. public static void RemoveDuplicates(DataTable tbl, DataColumn[] keyColumns)
  553. {
  554. int rowNdx = 0;
  555. while (rowNdx < tbl.Rows.Count - 1)
  556. {
  557. DataRow[] dups = FindDups(tbl, rowNdx, keyColumns);
  558. if (dups.Length > 0)
  559. {
  560. foreach (DataRow dup in dups)
  561. {
  562. tbl.Rows.Remove(dup);
  563. }
  564. }
  565. else
  566. {
  567. rowNdx++;
  568. }
  569. }
  570. }
  571. private static DataRow[] FindDups(DataTable tbl, int sourceNdx, DataColumn[] keyColumns)
  572. {
  573. ArrayList retVal = new ArrayList();
  574. DataRow sourceRow = tbl.Rows[sourceNdx];
  575. for (int i = sourceNdx + 1; i < tbl.Rows.Count; i++)
  576. {
  577. DataRow targetRow = tbl.Rows[i];
  578. if (IsDup(sourceRow, targetRow, keyColumns) || Is1stColumnEmpty(targetRow))
  579. {
  580. retVal.Add(targetRow);
  581. }
  582. }
  583. return (DataRow[])retVal.ToArray(typeof(DataRow));
  584. }
  585. private static bool IsDup(DataRow sourceRow, DataRow targetRow, DataColumn[] keyColumns)
  586. {
  587. bool retVal = true;
  588. foreach (DataColumn column in keyColumns)
  589. {
  590. retVal = retVal && sourceRow[column].Equals(targetRow[column]);
  591. if (!retVal) break;
  592. }
  593. return retVal;
  594. }
  595. private static bool Is1stColumnEmpty(DataRow sourceRow)
  596. {
  597. if (sourceRow[0].ToString().Equals(""))
  598. return true;
  599. else
  600. return false;
  601. }
  602. //private static bool Is2ndColumnEmpty(DataRow sourceRow)
  603. //{
  604. // if (sourceRow[1].ToString().Equals(""))
  605. // return true;
  606. // else
  607. // return false;
  608. //}
  609. //public static void RemoveProtEmpty(DataTable tbl)
  610. //{
  611. // DataRow[] blankRs = FindEmpty(tbl);
  612. // if (blankRs.Length > 0)
  613. // {
  614. // foreach (DataRow dup in blankRs)
  615. // {
  616. // tbl.Rows.Remove(dup);
  617. // }
  618. // }
  619. //}
  620. //private static DataRow[] FindEmpty(DataTable tbl)
  621. //{
  622. // ArrayList retVal = new ArrayList();
  623. // for (int i = 0; i < tbl.Rows.Count; i++)
  624. // {
  625. // DataRow targetRow = tbl.Rows[i];
  626. // if (Is1stColumnEmpty(targetRow) || Is2ndColumnEmpty(targetRow))
  627. // {
  628. // retVal.Add(targetRow);
  629. // }
  630. // }
  631. // return (DataRow[])retVal.ToArray(typeof(DataRow));
  632. //}
  633. /// <summary>
  634. /// Get the DataTable column names to an arraylist
  635. /// </summary>
  636. public static ArrayList DataTableColumns(DataTable dt, bool dataonly)
  637. {
  638. ArrayList marrCols = new ArrayList();
  639. int i = 0;
  640. foreach (DataColumn column in dt.Columns)
  641. {
  642. if (dataonly)
  643. {
  644. //Ignore MassTag column
  645. //if (i != 0 || !column.ColumnName.Equals("PepCount"))
  646. if (i != 0)
  647. marrCols.Add(column.ColumnName);
  648. i++;
  649. }
  650. else
  651. marrCols.Add(column.ColumnName);
  652. }
  653. return marrCols;
  654. }
  655. public static ArrayList DataTableColumns(DataTable dt, string dataset)
  656. {
  657. ArrayList marrCols = new ArrayList();
  658. int i = 0;
  659. bool prots = (dataset.Contains("pData") || dataset.Contains("qrollup"));
  660. foreach (DataColumn column in dt.Columns)
  661. {
  662. if (prots)
  663. {
  664. //Ignore first two columns
  665. if (i > 2)
  666. marrCols.Add(column.ColumnName);
  667. i++;
  668. }
  669. else
  670. {
  671. //Ignore the first column
  672. if (i != 0)
  673. marrCols.Add(column.ColumnName);
  674. i++;
  675. }
  676. }
  677. return marrCols;
  678. }
  679. public static ArrayList DataTableRows(DataTable dt)
  680. {
  681. ArrayList marrRows = new ArrayList();
  682. foreach (DataRow dRow in dt.Rows)
  683. {
  684. marrRows.Add(dRow.ItemArray[0].ToString());
  685. }
  686. return marrRows;
  687. }
  688. }
  689. }