- 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;
- }
- }