473,809 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlDataAdapter select command not returning correct results

1 New Member
Hi,

I'm having some trouble with the following piece of code:

Expand|Select|Wrap|Line Numbers
  1. string getAllNew = "SELECT * FROM dbo.HeaderAndDetail WHERE ProcessedToCsv = 0";
  2.             conn.Open();
  3.  
  4.             try
  5.             {
  6.                 SqlCommand cmd = new SqlCommand(getAllNew, conn);
  7.                 SqlDataAdapter dAdapter = new SqlDataAdapter();
  8.  
  9.                 dAdapter.SelectCommand = cmd;
  10.                 DataTable dTable = new DataTable();
  11.                 dAdapter.Fill(dTable);
  12.  
  13.                 cmd.Dispose();
  14.                 cmd = null;
  15.  
  16.                 WriteToCSV(dTable, filename);
  17.  
  18.                 dAdapter.Dispose();
  19.                 dAdapter = null;
  20.                 dTable.Dispose();
  21.                 dTable = null;
  22.             }
  23.             catch (Exception ex)
  24.             {
  25.                 throw new Exception(ex.ToString(), ex);
  26.             }
  27.             finally
  28.             {
  29.                 conn.Close();
  30.             }
The problem is that after the data table is filled, the rows in it include results that have ProcessedToCsv = 1 (not 0).

When I run the query (SELECT * FROM dbo.HeaderAndDe tail WHERE ProcessedToCsv = 0) in SQL server, it returns accurate results.
When that same query is the data adapter's select command, it returns everything.

What am I doing wrong? I've tried altering the query in code to the following:
SELECT * FROM dbo.HeaderAndDe tail WHERE ProcessedToCsv = @PTC (then adding a parameter and giving it a value before setting the select command of the data adapter)

SELECT * FROM dbo.HeaderAndDe tail WHERE ProcessedToCsv = 'False'

The above did not work.


FYI, "dbo.HeaderAndD etail" is a VIEW in my database. "ProcessedToCsv " is a BIT type column in my Detail TABLE. Playing around with those elements in SQL server is fine. Any query I execute returns accurate results.
I see no errors when I run the above code, or execute various queries in SQL server.

Would appreciate any help with this
Oct 17 '11 #1
1 6389
GaryTexmo
1,501 Recognized Expert Top Contributor
I'm wondering if your code is off... your data adapter doesn't get instantiated with the connection, you instead attach a command to it. I'm not sure if this is right... maybe it is, maybe it isn't (I don't have an SQL database to test with). Perhaps try this...

Expand|Select|Wrap|Line Numbers
  1. ...
  2. SqlDataAdapter dAdapter = new SqlDataAdapter(getAllNew, conn);
  3. dAdapter.Fill(dTable);
  4. ...
The only other thing I can think of is maybe try using the fully qualified field name. That's kinda a shot in the dark, but maybe there's something funny?

Expand|Select|Wrap|Line Numbers
  1. string getAllNew = "SELECT * FROM dbo.HeaderAndDetail WHERE dbo.HeaderAndDetail.ProcessedToCsv = 0";
Oct 18 '11 #2

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

Similar topics

2
1543
by: yawnmoth | last post by:
i'm using an entry in an sql database as a semaphore and it, unfortunately, doesn't appear to be working. the script that spawns the child processes has a for loop that performs the same basic sql query over and over again until the value has changed (there's a one second delay between each query). unfortunately, the resultant row is always the same, even when the other process *has* changed it. as an example, if the orig. value was of...
9
10774
by: Rowland Hills | last post by:
I have a table which is returning inconsistent results when I query it! In query analyzer: If I do "SELECT * FROM TABLE_NAME" I get no rows returned. If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned. In Enterprise manager:
7
3864
by: Dr John Stockton | last post by:
What are the best ways of returning multiple results from a subroutine ? I've been using ... return } which is inelegant. I'm used to Pascal's procedure X(const A, B : integer; var C, D : byte) ; where A, B are inputs only, and C, D are in/out.
1
1212
by: msnews.microsoft.com | last post by:
Hi All, When I use a SQL Query to Fill the Dataset if I use the following Where Clause ( > '100' ) Then I am getting a 'Data Type Mismatch Error' because the Field Type is double.
4
2840
by: Earl T | last post by:
When I try to get the netscape version for version 7, I get the HttpBrowserCapabilities class returning the version as 5 and not 7. (see code and output below) CODE HttpBrowserCapabilities bc; string s; bc = Request.Browser; ....
4
1266
by: Brian Mitchell | last post by:
I'm sure this is a very dumb question but when a user clicks on a row in my data table (which has been sorted) how do I return the correct row index for my underlying data table? The CurrentRowIndex property gives me the selected row of the data grid which no longer matches the data table when the columns have been resorted. Thanks!!!
6
10823
by: lcottrell | last post by:
I'll start off by saying I'm not very experienced in writing SQL commands. I am familiar with vbscript though, and I can do a similar thing in that, but can't seem to get it to work in SQL. What I need is to use Excel to connect to an SQL database and pull down information periodically, which I've been able to mostly do successfully. The problem now is that the information in some of the fields has extra information that makes it hard to read...
1
1766
by: thepresidentis | last post by:
here is my problem, i have a website that compiles concert listings for users to search for shows in their local area, i ran into a problem with returning search results due to an improper format of my query, So i formatted the query properly Thanks to steve Klein :) , and all worked fine because there was only 1 show in my data base, I tryed to search for the show and it returned properly, and then i searched for the show with a different...
2
1509
by: jfarthing | last post by:
Hi everyone, I am using a PERL script and am having some probs with it.... $query = sprintf ( "SELECT `Cats`.`Name`,`Address`.`Address`,`Address`.`City`,`Contact`.`Phone` FROM ( `Cats` LEFT JOIN `Address`
7
3135
by: seegoon | last post by:
Hi guys. I'm trying to write some php so that, depending on the page displayed, a certain <div> will load a certain class, giving it a certain background image. I have it down in theory, but there's a problem. My current code is returning multiple results as true, leading to the user receiving source like: <div id="wrap" class="flower-1flower-2"> In this instance, it is obviously supposed to be either class="flower-1" or class="flower-2"....
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10383
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.