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

  • Home
  • SEARCH
  • 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 7753269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:00:59+00:00 2026-06-01T12:00:59+00:00

I want to extracing a column from a database and save it into a

  • 0

I want to extracing a column from a database and save it into a list. Now it works but NULL value.
The column vlues in the original database are:

19506
19022
117037
NULL
1680
70659
1666
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
8113
NULL

You see there are a lot of “NULL”. I only want to get one “NULL”. My code’s result got many empty strings.

"19506"
"19022"
"117037"
""
"1680"
"70659"
"1666"
""
""
""
""
""
""
""
""
""
""
"8113"
""

What I want is:

"19506"
"19022"
"117037"
""
"1680"
"70659"
"1666"
"8113"

My code:

public static List<string> ExecuteReader(string commandtext,string col)
    {
        List<string> sRetVal = new List<string>();
        try
        {
            using (SqlConnection cnn = new SqlConnection(conn))
            {
                cnn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = cnn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = commandtext;

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            sRetVal.Add(reader[col].ToString());
                        }

                    }
                }
                cnn.Close();
            }
        }
        catch (Exception ex)
        {

        }
        return sRetVal.ToList().Distinct().ToList();
    }

Thanks.
UPDATED:
string commandtext = "select QO FROM [T1]";

  • 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-01T12:01:01+00:00Added an answer on June 1, 2026 at 12:01 pm

    Do the DISTINCT in the database, and it will handle this for you automatically:

    select DISTINCT COALESCE(QO,'NULL') FROM [T1]
    

    For the DISTINCT keyword, null values are considered to be duplicates of each other. When DISTINCT is included in a SELECT statement, only one NULL is returned in the results, regardless of how many null values are encountered.

    COALESCE:

    Returns the first nonnull expression among its arguments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am exctracting data from sqlite database and i need to transfer a column
I want to get the name and URLs from the first column of the
I am extracting the icon from .exes, but want to have a fallback generic
want to know why String behaves like value type while using ==. String s1
Want the function to sort the table by HP but if duplicate HPs then
So I'm extracting the lines that I want from this larger file using this
I'm extracting some information from an XML file, and I want to perform some
Extracting data from XML I want to preprocess one before sending it as a
In my Lazarus/Free Pascal application I generate a large multi-column numerical matrix. I want
I am extracting content from a web page using JS/JQuery and want to write

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.