Go: Determine if the dataset is empty

Source: Internet
Author: User

http://blog.sina.com.cn/jiangshuqin2010

1,if (ds = = null) This is to determine if the data set in memory is empty, the dataset is empty, the rows and columns do not exist!!

2,if (ds. Tables[0]. Count = = 0) This should be a dataset in memory, but there is no table in the DataSet!!

3,if (ds. Tables[0]. Count = = 1 && ds. Tables[0]. Rows.Count = = 0) indicates that there are table tables, but there is no data in the table!

1 if(yourdataset.tables[0]. Rows.Count >0   )2 {3 //What you have to do when you have a record4 }5 Else6 {7 //Return empty Set8 }9 if(dataset1.tables[0]. Rows.Count = =0)Ten { OneResponse.Write ("<script language=javascript>alert (' No record! '); </script>"); A}

Recommendation (Yourdataset.tables[0]. Rows.Count > 0) or (ds.tables==null) should first determine if the dataset is empty (when a query is faulted), and then determine whether the number of rows in the table is 0 (the query is not faulted and the number of rows is 0), otherwise error-prone,
For example: First Judge Mydataset.tables[0]. Rows.count==0, if the query error, at this time mydataset is null, there is no table, so will error.
So it should be judged

 1  if  (myDataSet = null  | | Mydataset.tables[0 ]. Rows.Count = = 0  )  2  { 3  //  4   5  else  6  { //  not empty when handling  8 } 

"| |" and the "&&" Operation Mr. Foo judge the first condition, not satisfied and then judge the next condition, but if the above order exchange in myDataSet is NULL, it will be wrong, that is, first judge the big condition, then judge the small condition

Go: Determine if the dataset is empty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.