标签:style blog class code c java
判断DataTable中某列是否包含某值
/// <summary> /// 判断DataTable中是否包含某值 /// </summary> /// <param name="dt">DataTable</param> /// <param name="columnName">列名</param> /// <param name="fieldData">值</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; } } }
向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
C# DataTable 相关操作,布布扣,bubuko.com
标签:style blog class code c java
原文地址:http://www.cnblogs.com/iwenr/p/3725300.html