How to check empty DataTable

后端 未结 8 650
孤城傲影
孤城傲影 2020-12-10 10:15

I have a DataSet where I need to find out how many rows has been changed using the following code:

dataTable1 = dataSet1.Tables[\"FooTable\"].Ge         


        
8条回答
  •  醉话见心
    2020-12-10 10:52

    If dataTable1 is null, it is not an empty datatable.

    Simply wrap your foreach in an if-statement that checks if dataTable1 is null. Make sure that your foreach counts over DataTable1.Rows or you will get a compilation error.

        if (dataTable1 != null)
        {
           foreach (DataRow dr in dataTable1.Rows)
           {
              // ...
           }
        }
    

提交回复
热议问题