Determines whether a column in the DataTable contains a value.
/// <Summary> /// determine whether the DataTable contains a certain value // </summary> /// <param name = "dt"> DataTable </param>/ // <param name = "columnName"> column name </param> // <param name = "fieldData"> value </param> /// <returns> </returns> public Boolean IsColumnIncludeData (DataTable dt, string columnName, string fieldData) {if (dt = null) {return false;} else {DataRow [] dataRows = dt. select (columnName + "= '" + fieldData + "'"); if (dataRows. length. equals (1) {return true;} else {return false ;}}}
Add data to DataTable
DataTable dt = null; dt = handle.ExecuteDataTable(sql, true); #region DataRow dr; for (int i = 0; i < code.Length; i++) { if (IsColumnIncludeData(dt, "SystemCode", code[i]) == false) { dr = dt.NewRow(); dr[0] = name[i]; dr[1] = code[i]; dr[2] = 0; dt.Rows.Add(dr); } } #endregion