0

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.

Edited by __avd: Added [code] tags.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by __avd
0

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;

Edited by happygeek: fixed formatting

0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.