473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
Expand|Select|Wrap|Line Numbers
  1.  public static DataSet FillCat2(string current, string previous, string choice)
  2.         {
  3.             DataSet dt = new DataSet();
  4.             string conString = ConfigurationManager.ConnectionStrings[""].ToString();
  5.             try
  6.             {
  7.                 using (SqlConnection conn = new SqlConnection(conString))
  8.                 {
  9.                     SqlCommand comm = new SqlCommand("select distinct " + current + " from ourcategories where " + previous + "='" + choice + "' order by " + current, conn);
  10.  
  11.                     SqlDataAdapter sda = new SqlDataAdapter(comm);
  12.                     sda.Fill(dt);
  13.  
  14.                     return dt;
  15.                 }
  16.             }
  17.             catch (Exception e)
  18.             {
  19.                 ExceptionLogger.LogException(e);
  20.                 throw e;
  21.             }
  22.  
  23.         }
  24.  
Thanks in advance for all the help.
Jan 5 '11 #1
2 1277
Sfreak
64
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?
Jan 6 '11 #2
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.
Jan 6 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Brent | last post by:
In the usual case, this SQL select count(*) from mytable where ... returns an accurate count of the rows you want. But how do I go about counting rows from this SQL (the sum...if statements...
1
by: neil rowe | last post by:
Hi Has anyone else had this problem. Im using a vb .net dataset to read & write XML but when I check the number of rows for a table it's incorrect. Example number of rows = 4 table row...
1
by: CB | last post by:
Using C# in .Net 2003, DataSet.ReadXml fails when a percentage (%) sign is in the filename followed by 2 hex characters. Seems that the % sign is likely encoding the following 2 hex characters. ...
0
by: KGrein | last post by:
Hi. I have a form that contains a combo box with customer number & customer name in it. The form is called F_DeleteUSCust and the combo box is named CB_getUScust It picks up the information for...
1
by: Marisha | last post by:
Hi Guys, I have some question, I have datadrid that bound to dataset,the data in data set filled from text file (not from database) User may update some data in datagrid,then I need to update...
3
by: Sam | last post by:
Hi, I've got a datagrid and a dataset used as the datasource. I'd like to do a test, if the index of the selected row in the grid is greater than the dataset.tables(0).rows.count. The problem is...
2
by: Katie | last post by:
I have created a report which sorts data by a time frame. However, if there is no data for a particular time frame then that row does not show. I need it to show with a blank for the value, e.g....
4
by: SteveT | last post by:
I am trying to create a dataset from an XML file. When calling myDataSet.ReadXml("sample.xml") the code produces an exception error. The XML file has many strings that identify pnp ids on a...
1
by: asrir | last post by:
If there are no records returned by the sql what should be the value of myDataSet.Tables.Count. Is it 0 or 1 (with rows count 0)? The same application returns 0 on one machine and 1 on another. We...
4
by: Lint Radley | last post by:
Hello, My project contains a dataset which accesses an MDF database file created within the project. When debugging the program, everything works great. However, when I publish and install the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.