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();
                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);

                    return dt;
            catch (Exception e)
                throw e;


Thanks in advance for all the help.

Recommended Answers

All 3 Replies

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, learning, and sharing knowledge.