dataset showing count as 1 when should be 0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • readbanana
    New Member
    • Jul 2010
    • 37

    dataset showing count as 1 when should be 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.
    Code:
     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.
    Last edited by Stewart Ross; Jan 5 '11, 03:30 PM. Reason: Fixed code tags
  • Sfreak
    New Member
    • Mar 2010
    • 64

    #2
    In this case you must check the data in your DB.
    1 - Did you test you SQL sentence directly in your db interface to see the real return?
    2 - Did you check your app.config to see if the BD you are testing is the same that you are connecting?

    Comment

    • readbanana
      New Member
      • Jul 2010
      • 37

      #3
      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. Thanks so much for help.

      Comment

      Working...