151
技術社區[雲棲]
C# 判斷DATASET是否為空
if (ds == null) MessageBox.Show("內存中的數據集為空,說明DATASET為空,行和列都不存在!!"); if (ds.Tables.Count == 0) MessageBox.Show("內存中存在一個DATASET,但是,數據集中不存在表!!"); if (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0) MessageBox.Show("存在表table,但是,表內沒有數據!");
實用:
/// <summary> /// 判斷DS是否為空 /// </summary> /// <param name="ds">需要判斷的ds</param> /// <returns>如果ds為空,返回true</returns> private bool JudgeDs(DataSet ds) { bool Flag=false; if ((ds == null) || (ds.Tables.Count == 0) || (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0)) { Flag = true; } return Flag; }升級版:
/// <summary> /// 檢查一個DataSet 裏麵是否含有數據 /// </summary> /// <param name="ds">要檢測的DataSet</param> /// <param name="tableIndex">DataSet裏Table的索引</param> /// <returns>True: 裏麵有數據。 False:裏麵沒有數據</returns> public static bool IfExitData(DataSet ds,int tableIndex) { if(ds!=null&&ds.Tables[tableIndex].Rows.Count>0) { return true; } else { return false; } }
最後更新:2017-04-03 12:54:06