I am filling a dataset from a database. When there are no rows to return it still tells me that the count is 1. I can't figure out what is going wrong. if I look at a visual of the dataset, the row is blank, but the count is 1.

public static DataSet FillCat2(string current, string previous, string choice)
        {
            DataSet dt = new DataSet();
            string conString = ConfigurationManager.ConnectionStrings[""].ToString();
            try
            {
                using (SqlConnection conn = new SqlConnection(conString))
                {
                    SqlCommand comm = new SqlCommand("select distinct " + current + " from ourcategories where " + previous + "='" + choice + "' order by " + current, conn);

                    SqlDataAdapter sda = new SqlDataAdapter(comm);
                    sda.Fill(dt);

                    return dt;
                }
            }
            catch (Exception e)
            {
                ExceptionLogger.LogException(e);
                throw e;
            }

        }

Thanks in advance for all the help.

Please use BB code tags while posting source program.

dataset showing count as 1 when should be 0

This statement return 1 (count of tables)

int c=dt.Tables.Count;

This statement return 1 or 0 (rows count)

int c=dt.Tables[0].Rows.Count;

I realized that I wasn't filtering by if it was null. so when there was nothing to fill the dataset it was returning a null row. When I filtered by null it works perfectly.

Have you figure out that issue? Please mark this thread as solved if you have found an answer to your question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.