Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

dataTable1 = dataSet1.Tables["FooTable"].GetChanges();

foreach (DataRow dr in dataTable1)
{
  // ...
}

DataSet has DataSet.HasRow but DataTable doesn't have such method. If there is no changed rows. changedDT1 will be a null value, causing the loop to throw exception.

How do I check if DataTable is empty? I tried Rows.Count - doesn't work...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
193 views
Welcome To Ask or Share your Answers For Others

1 Answer

First make sure that DataTable is not null and than check for the row count

if(dt!=null)
{
  if(dt.Rows.Count>0)
  {
    //do your code 
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...