Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:17:34+00:00 2026-06-03T23:17:34+00:00

Anyone can guide me a way to check and replace null values in strList

  • 0

Anyone can guide me a way to check and replace null values in strList with String message “NO DATA” or allow them in dtList.
Because when I met a null value in this List,it show an error like “There is no row at position…”

private DataTable getSomething1(String text){
    DataTable dtb = new DataTable();
    ...
    ...
    return dtb;
}

...

protected void buttonCheck_Click(object sender, ImageClickEventArgs e){
    List<DataTable> strList = new List<DataTable>(){
        getSomething(txtInput.Text),
        getSomething2(txtInput.Text),
        getSomething3(txtInput.Text),
        ...                
    };
}

I used C# in Webform.
Plz, help me to fix this code or guide me a way to solve it.
Thanks in advance.

@tech, @ riffnl: Finally I get all of your ideas and it really work now. Anw, thanks all pro here for advices. So, this is my solution ^^

private String ConvertNullToEmptyString(DataTable element)
    {
        if (element.Rows.Count > 0) //just add this condition here
        {
            if (!DBNull.Value.Equals(element.Rows[0]["FullName"]))
                return (string)element.Rows[0]["FullName"] + " ";
            else
                return String.Empty;
        }
        return "NO DATA";
    }

protected void ....(){
     List<DataTable> strList = new List<DataTable>(){
       GetItem1(txtName.Text),   //private DataTable GetItem1(String t)
       GetItem2(txtName.Text),   //...           
     };

    txtGrD_D.Text = ConvertNullToEmptyString(strList[0]);
    txtGrM_D.Text = ConvertNullToEmptyString(strList[1]);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:17:35+00:00Added an answer on June 3, 2026 at 11:17 pm

    Since you’re using a datatable I assume you’re not talking about NULL (or nill), but DBNull..
    Change your function ConvertNullToEmptyString like this:

    private String ConvertNullToEmptyString(DataTable element){ 
      if (element.Rows[0]["Fullname"] == DBNull.Value || element.Rows[0]["Fullname"] == null) {
        return "NO DATA";
      } else {
        return element.Rows[0]["Fullname"].ToString();
      }
    }
    

    as requested: new sample;

    // a list of datatables each containing 1 row, wasn't that the point of datatables
        // anyway -- I think you don't have any rows, so let's try this:
        private String ConvertNullToEmptyString(DataTable element)
        {
            if (element.Rows.Count == 0)
            {
                return "NO DATA";
            }
            if (element.Rows[0]["Fullname"] == DBNull.Value || element.Rows[0]["Fullname"] == null)
            {
                return "NO DATA";
            }
            else
            {
                return element.Rows[0]["Fullname"].ToString();
            }
        } 
        protected void Test()
        {
            List<DataTable> strList = new List<DataTable>(){ 
               GetItem("test1"),   //private DataTable GetItem1(String t) 
               GetItem("test2")   //...            
             };
            txtGrD_D.Text = ConvertNullToEmptyString(strList[0]);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone guide me through the right way to add an existing Helper into
Can anyone point me in the way of a guide/tutorial on how to limit
Can anyone guide me in the correct way to build a colored bubble/circle programmatically?
Can anyone guide me in the best way of developing a filter algorithm for
Can anyone guide me what could be the problem in the mentioned below:- alt
Can anyone point me to a guide for creating inf files? In particular, I'm
Does anyone know of an ASP.NET guide to implementing OpenID and what information can
Can anyone guide how to display map on MapView with iframe code. I try
Hi can anyone guide me in this problem ? I am reading a .class
Can anyone advise what is the best way of client and server side validation.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.