Checking if a datatable is null

后端 未结 7 1876
南旧
南旧 2021-02-19 22:02

The following code is what I\'ve been using to retrieve user information from a sql database.

            string userName = LoginUser.UserName;
            strin         


        
7条回答
  •  南旧
    南旧 (楼主)
    2021-02-19 22:33

    It will be better if you use try catch for checking whether the table is empty or not , just handle the IndexOutOfRangeException exception.

    Use the following logic:

    try
    {
       //dataTable operations
    }
    catch(IndexOutOfRangeException)
    {
    }
    

    For me its working.

提交回复
热议问题